我想使用自定义对话框作为注册表单在firebase数据库中注册用户。我已经在此登录活动中使用了Google登录选项。我已经启用了firebase控制台中的登录方法错误。实际上我不想使用这个活动,因为我需要转移到另一个活动..我想要像Ui一样的屏幕叠加。请帮我解决这个错误,或者给出更好的替代方案..提前致谢
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms:com.google.android.gms.internal.zzdze@adc412
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
[FirebaseAuth:] Preparing to create service connection to gms implementation
V/RenderScript: 0xb8012c38 Launching thread(s), CPUs 8
W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.android.gms.internal.zzdze@adc412
Login.kt
lateinit var mGoogleSignInClient: GoogleSignInClient
private val RC_SIGN_IN = 1
lateinit var googleLoginBtn: SignInButton
lateinit var mAuth: FirebaseAuth
lateinit var gso: GoogleSignInOptions
lateinit var mDatabase: DatabaseReference
lateinit var mProgressDialog: ProgressDialog
var name1: EditText? = null
var email1: EditText? = null
var pass1: EditText? = null
var confpass1: EditText? = null
var loginT: TextView? = null
var email2: EditText? = null
var pass2: EditText? = null
lateinit var mAuthStateListener: FirebaseAuth.AuthStateListener
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
mProgressDialog = ProgressDialog(this)
name1 = findViewById(R.id.editFullName)
email1 = findViewById(R.id.editEmail)
pass1 = findViewById(R.id.editPass)
confpass1 = findViewById(R.id.editPassConfirm)
loginT = findViewById(R.id.textL)
email2 = findViewById(R.id.editTextEmail)
pass2 = findViewById(R.id.editTextPass)
googleLoginBtn = findViewById(R.id.gLoginBtn)
mAuth = FirebaseAuth.getInstance()
val emailBtn = findViewById<Button>(R.id.emailPasswordBtn)
mAuthStateListener = FirebaseAuth.AuthStateListener {
if (it.currentUser != null) {
startActivity(Intent(applicationContext, MainActivity::class.java))
finish()
}
}
gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build()
mGoogleSignInClient = GoogleSignIn.getClient(this, gso)
googleLoginBtn.setOnClickListener {
signIn()
}
emailPasswordBtn.setOnClickListener {
val dialogBuilder = AlertDialog.Builder(this@Login)
val view = layoutInflater.inflate(R.layout.register_custom_dialog, null)
dialogBuilder.setView(view)
val alertDialog = dialogBuilder.create()
alertDialog.show()
view.regBtn.setOnClickListener {
//regDetail()
val name = name1?.text.toString().trim()
val email = email1?.text.toString().trim()
val pass = pass1?.text.toString().trim()
val confpass = confpass1?.text.toString().trim()
if (TextUtils.isEmpty(name)) {
name1?.error = "Field Required!"
return@setOnClickListener
}
if (TextUtils.isEmpty(email)) {
email1?.error = "Field Required!"
return@setOnClickListener
}
if (TextUtils.isEmpty(pass)) {
pass1?.error = "Field Required!"
return@setOnClickListener
}
if (TextUtils.isEmpty(confpass)) {
pass1?.error = "Field Required!"
return@setOnClickListener
}
createUser(name, email, pass)
}
}
}
createUser()函数
private fun createUser(name: String, email: String, pass: String) {
mProgressDialog.setMessage("Registering..")
mProgressDialog.show()
mAuth.createUserWithEmailAndPassword(email, pass)
.addOnCompleteListener(this) { task: Task<AuthResult> ->
if (task.isSuccessful) {
val currentUser = mAuth.currentUser
val uid = currentUser!!.uid
val userMap = HashMap<String, String>()
userMap["name"] = name
userMap["email"] = email
userMap["image"] = "image"
mDatabase = FirebaseDatabase.getInstance().getReference("Users").child(uid)
mDatabase.setValue(userMap).addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
val intent = Intent(applicationContext, MainActivity::class.java)
startActivity(intent)
mProgressDialog.dismiss()
}
}
Toast.makeText(this@Login, "Authentication Success!!", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this@Login, "Authentication Failed!!", Toast.LENGTH_SHORT).show()
mProgressDialog.dismiss()
}
// ...
}
}
override fun onStart() {
super.onStart()
mAuth.addAuthStateListener(mAuthStateListener)
}
register_custom_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">
<EditText
android:id="@+id/editFullName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:ems="10"
android:hint="Full Name"
android:inputType="textPersonName" />
<EditText
android:id="@+id/editEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editFullName"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/editPass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editEmail"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword" />
<EditText
android:id="@+id/editPassConfirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editPass"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:ems="10"
android:hint="Confirm Password"
android:inputType="textPassword" />
<TextView
android:id="@+id/textL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editPassConfirm"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:gravity="center_horizontal"
android:text="Login using E-mail"
android:textSize="16dp" />
<Button
android:id="@+id/regBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textL"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:textAllCaps="false"
android:text="Register" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignStart="@+id/editFullName"
android:layout_marginTop="10dp"
android:text="Register"
android:textSize="24sp" />
</RelativeLayout>
Gradle Dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.google.firebase:firebase-auth:12.0.1'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.google.firebase:firebase-database:12.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'