Firebase not working. Android

烈酒焚心 提交于 2019-12-12 17:24:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!