【发布时间】:2020-01-31 09:10:40
【问题描述】:
我正在尝试通过 Android 向 Firebase 添加一个新用户,但我收到一条对我来说没有意义的错误消息。我在 Firebase 控制台中启用了电子邮件/密码登录。我收到的错误消息是:
com.example.myproject D/RegisterActivity: validateForm: LoginActivity validateForm 已启动。 com.example.myproject I/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() 返回 Gms:com.google.firebase.auth.api.internal.zzao@xyz123
com.example.myproject W/FirebaseMethods: createUserWithEmail: 失败 com.google.firebase.FirebaseException:发生内部错误。 [7:]
我的代码库如下:
public class FirebaseMethods {
private static final String TAG = "FirebaseMethods";
// declare Firebase auth
private FirebaseAuth mAuth;
private String user;
private Context mContext;
public FirebaseMethods(Context context){
mAuth = FirebaseAuth.getInstance();
mContext = context;
if(mAuth.getCurrentUser() != null){
user = mAuth.getCurrentUser().getUid();
}
}
/**
* Register a new username and email to Firebase authentication
* @param email
* @param password
* @param username
*/
public void registerNewEmail(String email, String password, String username){
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(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();
updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "createUserWithEmail:failure", task.getException());
Toast.makeText(mContext, "Authentication failed.", Toast.LENGTH_SHORT).show();
updateUI(null);
}
}
});
}
private void updateUI(FirebaseUser user) {
Log.d(TAG, "updateUI: LoginActivity updateUI started.");
if (user != null) {
/*If the user is already logged in then navigate back to the MainActivity.*/
Intent intent = new Intent(mContext, MainActivity.class);
mContext.startActivity(intent);
} else {
//add alternative action here
}
}
【问题讨论】:
-
您是否从 Fire Base 控制台开启
authentication? -
我把它打开了。查看更新的照片。我认为问题出在我的代码中。
标签: android firebase firebase-authentication