Firebase无法正常工作。的Android

时间:2017-02-03 00:12:29

标签: android firebase firebase-authentication

我试图注册一个用户,但它没有用。当我检查console.firebase时,尚未创建用户。 这是我的代码:

    //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");
                  }
              }
          });

enter image description here

It's in portuguese, but says "actived" in the status

2 个答案:

答案 0 :(得分:5)

我解决了这个问题!我在android studio模拟器中测试我的应用程序。这就是问题,我将APK下载到我的手机上,它运行正常!

答案 1 :(得分:2)

好像你还没有添加听众:

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遵循https://firebase.google.com/docs/auth/android/start/

的完整教程