1
所以我實現了Facebook登錄,現在我已經實現了Google。它已成功登錄,但是當我重新啓動應用程序時,用戶必須重新登錄。但是,如果我使用FB登錄,則它應該如此。 這裏是我的AuthListener
:Android應用Facebook登錄記住用戶,但Google登錄不會
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
Log.d("AD", "User is logged in.");
SignUp.this.startActivity(startMainActivity);
} else {
Log.d("AD", "User is not logged in.");
}
}
};
和其他一切做與谷歌登錄:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Toast.makeText(SignUp.this, "There has been an error connecting to Google: " + connectionResult.getErrorMessage(), Toast.LENGTH_LONG).show();
}
} /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
signInButton.setOnClickListener(this);
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mCallbackManager.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
private void handleSignInResult(GoogleSignInResult result) {
Log.d("AD", "Signed in via google successfully:" + result.isSuccess());
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
this.startActivity(startMainActivity);
} else {
// Signed out, show unauthenticated UI.
Toast.makeText(this, "An error has occurred", Toast.LENGTH_SHORT).show();
}
}
這很奇怪;我總是遇到Google的麻煩,而且別無其他:{