I am creating an Android app using Firebase.
If you want to use Firebase, you should do Google authentication and then Firebase authentication.
GoogleSignInResult.isSuccess() from the source below returns false, so I cannot log in.
Also, GoogleSignInResult.getStatus().getStatusMessage() returns null, so we don't know why.
I'm sorry to trouble you, but could you tell me how to log in?
·If you manually install the release.apk created with Generate Signed APK on the actual machine via USB cable with adb install release.apk, you can do Google authentication.
However, if you publish it as a release in the Google Play Store and install it through the Google Play Store, you will not be able to authenticate with Google.
(At first, it was released as a beta version, but it could have been caused by the beta version, so we released it as a release version.)
·SHA1 in release.apk is registered in FireBase>Project Setting>SHA certificate fingerprints.
List 1: Screen Images (After Pressing the Login Button)
List 2: Source (GoogleSignInResult.isSuccess() returns false in onActivityResult)
public class LoginActivity extensions AppCompatActivity{
private static final int REQUEST_CODE_SIGN_IN=9001;
private FirebaseAuth firebaseAuth;
public static GoogleApiClient googleAPIClient;
private DatabaseReference usersRef;
private ProgressDialog progressDialog;
private GoogleApiClient.OnConnectionFailedListener onConnectionFailedListener=newGoogleApiClient.OnConnectionFailedListener(){
@ Override
public void onConnectionFailed(@NonNullConnectionResult connectionResult){
Toast.makeText(LoginActivity.this, "Google Play Services error.", Toast.LENGTH_SHORT).show();
}
};
@ Override
public void onCreate (Bundle savedInstanceState) {
System.out.println("***LoginActivity.onCreate-start");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
try{
progressDialog = new ProgressDialog(this);
GoogleSignInOptions options=new GoogleSignInOptions.Builder (GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
GoogleAPICclient=newGoogleApiClient.Builder(this)
.enableAutoManage(this, onConnectionFailedListener)
.addApi(Auth.GOOGLE_SIGN_IN_API, options)
.build();
firebaseAuth=FirebaseAuth.getInstance();
} catch(Exceptione){
e.printStackTrace();
}
System.out.println("***LoginActivity.onCreate-start");
}
@ Override
public void onStop() {
System.out.println("LoginActivity.onStop-start");
if(null!=usersRef){
usersRef.removeEventListener(valueEventListener);
}
super.onStop();
}
public void onCancelButtonClick (View view) {
finish();
}
public void onLoginButtonClick (View view) {
System.out.println("***LoginActivity.onLoginButtonClick-start");
Intent=Auth.GoogleSignInApi.getSignInIntent(googleAPIClient);
startActivityForResult(intent,REQUEST_CODE_SIGN_IN);
System.out.println("***LoginActivity.onLoginButtonClick-end");
}
@ Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
System.out.println("***LoginActivity.onActivityResult-start");
if(requestCode==REQUEST_CODE_SIGN_IN){
System.out.println("***LoginActivity.onActivityResult-in if");
GoogleSignInResult result=Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if(result.isSuccess()){
System.out.println("***LoginActivity.onActivityResult-in if success";
GoogleSignInAccount=result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else{
System.out.println("***LoginActivity.onActivityResult-in error");
System.out.println("***LoginActivity.onActivityResult-in error state:"+result.getStatus().getStatusMessage());
Toast.makeText(LoginActivity.this, "Error:" +result.getStatus().getStatusMessage(), Toast.LENGTH_SHORT).show();
}
}
System.out.println("***LoginActivity.onActivityResult-end");
}
public void firebaseAuthWithGoogle(GoogleSignInAccount account){
// firebase authentication
}
}
It seems that it has already been solved by an overseas question, but the answer was in English, so I will translate it freely.
Isn't there a SHA1 fingerprint in the Firebase setting?
It seems that the signature key of the application was not authenticated by Firebase.
© 2024 OneMinuteCode. All rights reserved.