Android Studio中使用Firebase创建新用户失败求助
Firebase注册用户失败问题排查
我没有收到任何报错信息,代码是从官方文档及教程复制而来,但点击注册按钮后显示注册失败。
已完成以下操作:
- 在Manifest文件中添加了权限
- 在Firebase控制台开启了邮箱/密码认证
- 按照规范流程完成注册配置
我希望能成功注册并在Firebase控制台查看用户,同时能在Firebase上查看注册的邮箱和密码。
代码如下:
package com.example.auth; import static androidx.constraintlayout.widget.StateSet.TAG; import com.google.firebase.auth.AuthResult; import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseUser; public class MainActivity extends AppCompatActivity { EditText email,password,confirmpasswordreg; Button register; TextView alreadylogin; FirebaseAuth mauth; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); email=findViewById(R.id.editTextTextEmailAddressreg); password=findViewById(R.id.passwordregister); alreadylogin=findViewById(R.id.textView4reg); register=findViewById(R.id.buttonreg); confirmpasswordreg=findViewById(R.id.cnfmpassreg); mauth=FirebaseAuth.getInstance(); register.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String username=email.getText().toString(); String passwords=password.getText().toString(); String confirmpassword=confirmpasswordreg.getText().toString(); mauth.createUserWithEmailAndPassword(username,passwords) .addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information Log.d(TAG, "createUserWithEmail:success"); FirebaseUser user = mauth.getCurrentUser(); Toast.makeText(MainActivity.this, "sign up success", Toast.LENGTH_SHORT).show(); } else { // If sign in fails, display a message to the user. Log.w(TAG, "createUserWithEmail:failure", task.getException()); Toast.makeText(MainActivity.this, "sign up failed", Toast.LENGTH_SHORT).show(); } }); } } }); } }
内容的提问来源于stack exchange,提问作者Mohommed Habib
相关产品推荐
相关产品推荐

