Google Login API not working when debugging on device

I currently have a google subscription API working flawlessly through Android Studio Debugger, and when I install the APK on my Samsung S6. But when I try to debug the connection via USB, GoogleSignInResult.isSuccess () always returns false.

This is a little annoying because I need to debug another function that seems to work very well when debugging through Android studio, but not on my device, and I can't get past my login screen. -_-

Here is a block of code that fails, and I can provide more pieces of code if necessary.

// [START handleSignInResult]
private void handleSignInResult(GoogleSignInResult result) {
    Log.d(TAG, "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
        // Signed in successfully, show authenticated UI.
        GoogleSignInAccount acct = result.getSignInAccount();
        Intent myIntent = new Intent(getApplicationContext(), MainActivity.class);

        myIntent.putExtra("account", acct);
        startActivity(myIntent);
        finish();
    }
}
// [END handleSignInResult]

// [START signIn]
private void signIn() {
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    startActivityForResult(signInIntent, RC_SIGN_IN);
}
// [END signIn]

// [START onActivityResult]
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        handleSignInResult(result);
    }
}
// [END onActivityResult]

Thanks!

+4
source share

Source: https://habr.com/ru/post/1618226/


All Articles