问题
I was trying to register an user but it didn't work. When I check the console.firebase the user has not been created. Here is my code:
//registering
firebaseAuth.createUserWithEmailAndPassword("trying@gmail.com", "justtesting")
.addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Log.i("test", "success");
}
else{
Log.i("test", "did not work");
}
}
});
回答1:
Seems like you have not added the listeners:
private FirebaseAuth.AuthStateListener mAuthListener;
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
// ...
}
};
@Override
public void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
@Override
public void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
Plesae follow the complete tutorial at https://firebase.google.com/docs/auth/android/start/
回答2:
I solved the problem! I was testing my app in the android studio emulator. That was the issue, I downloaded the APK to my phone and it is working perfectly!
来源:https://stackoverflow.com/questions/42014682/firebase-not-working-android