使用Firebase Auth UI进行身份验证无效

时间:2017-01-13 22:03:55

标签: android firebase-authentication

我按照Firebase in a weekend

中的说明操作

当我启动应用时,系统会要求我选择一个帐户。但是当我选择帐户时,同一层会一次又一次地出现。发生在模拟器和真实设备上。

enter image description here

在课程中它看起来像这样:

enter image description here

你有任何提示吗?

编辑: MainActivity.java:     包de.marcofriedmann.testlabor:

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.firebase.ui.auth.AuthUI;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

import java.util.Arrays;

public class MainActivity extends AppCompatActivity {

private FirebaseAuth mFirebaseAuth;
private FirebaseAuth.AuthStateListener mAuthStateListener;

// Choose an arbitrary request code value
private static final int RC_SIGN_IN = 1;

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

    // initialize Firebase
    mFirebaseAuth = FirebaseAuth.getInstance();

    mAuthStateListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is logged in
                String username = firebaseAuth.getCurrentUser().getDisplayName();
                TextView welcomeText = (TextView) findViewById(R.id.welcome);
                welcomeText.setText(username);
            } else {
                // User is logged out
                startActivityForResult(
                        AuthUI.getInstance()
                                .createSignInIntentBuilder()
                                .setIsSmartLockEnabled(false)
                                .setProviders(Arrays.asList(
                                        new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build()))
                                .build(),
                        RC_SIGN_IN);
            }
        }
    };

}

@Override
protected void onPause() {
    super.onPause();
    mFirebaseAuth.removeAuthStateListener(mAuthStateListener);
}

@Override
protected void onResume() {
    super.onResume();
    mFirebaseAuth.addAuthStateListener(mAuthStateListener);
}

}

0 个答案:

没有答案