FireBase signInWithEmailAndPassword什么都不做

时间:2018-08-10 18:44:48

标签: android firebase firebase-authentication

开始使用Android Studio编写应用程序时,我遇到了有关firebase登录命令的问题。该应用程序已连接到Firebase,并且用户列表包含为“ mail”和“ pw”提供的字符串。方法“ login()”应该返回两条消息之一,但是什么也没有发生(甚至日志中也没有错误消息)。代码如下:

public class MainActivity extends AppCompatActivity {

    FirebaseAuth firebaseAuth;
    Dialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        FirebaseApp.initializeApp(this);
        firebaseAuth = FirebaseAuth.getInstance();
        if (firebaseAuth.getCurrentUser() == null) {
            logIn();
        }
    }

    private void logIn() {
        String mail = "example@gmail.com";
        String pw = "password";
        firebaseAuth.signInWithEmailAndPassword(mail, pw)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                       @Override
                       public void onComplete(@NonNull Task<AuthResult> task) {
                           if (task.isSuccessful()) {
                               Toast.makeText(getApplicationContext(), "Login successful", Toast.LENGTH_LONG).show();
                           } else {
                               Log.w("Sign in error: ", task.getException());
                               Toast.makeText(getApplicationContext(), "Login unsuccessful", Toast.LENGTH_LONG).show();
                           }
                       }
                   });    
    }
}

0 个答案:

没有答案