I am developing the application where I am trying to login using Google. But getExtrasdata always returns null.
Here is what I have from log:
getSignInIntent = { act=com.google.android.gms.auth.GOOGLE_SIGN_IN cmp=com.rbsoftware.pfm.personalfinancemanager/com.google.android.gms.auth.api.signin.internal.SignInHubActivity (has extras) }
mGoogleApiClient=com.google.android.gms.internal.zzmg@1f595441
handleSignInResult:false
result=com.google.android.gms.auth.api.signin.GoogleSignInResult@7d8c188
data=Intent { (has extras) }
getExtrasdata=Bundle[{googleSignInStatus=Status{statusCode=INTERNAL_ERROR, resolution=null}}]
Everything should be ok in Developer Console.
Could you please help me to fix this issue?
package com.rbsoftware.pfm.personalfinancemanager;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.OptionalPendingResult;
import com.google.android.gms.common.api.ResultCallback;
public class LoginActivity extends AppCompatActivity implements
GoogleApiClient.OnConnectionFailedListener,
View.OnClickListener {
private static final String TAG = "SignInActivity";
private static final int RC_SIGN_IN = 9001;
public GoogleApiClient mGoogleApiClient;
private ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// Button listeners
findViewById(R.id.sign_in_button).setOnClickListener(this);
// [START configure_signin]
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
// [END configure_signin]
// [START build_client]
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
// [END build_client]
// [Button]
SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
signInButton.setSize(SignInButton.SIZE_WIDE);
signInButton.setScopes(gso.getScopeArray());
}
@Override
public void onStart() {
super.onStart();
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
if (opr.isDone()) {
Log.d(TAG, "Got cached sign-in");
GoogleSignInResult result = opr.get();
handleSignInResult(result);
} else {
opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
@Override
public void onResult(GoogleSignInResult googleSignInResult) {
handleSignInResult(googleSignInResult);
}
});
}
}
// [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]
// [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 intent = new Intent(this, MainActivity.class);
intent.putExtra("name", acct.getDisplayName());
intent.putExtra("id", acct.getId());
intent.putExtra("email", acct.getEmail());
intent.putExtra("photoURL", acct.getPhotoUrl());
Log.d("USER Pic", acct.getPhotoUrl()+"");
startActivity(intent);
finish();
} else {
}
}
// [END handleSignInResult]
// [START signIn]
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
// [END signIn]
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.d(TAG, "onConnectionFailed:" + connectionResult);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
signIn();
break;
}
}
}
The SHA1 fingerprint of keystore is corrupt. You have changed ~/.android/ ?, have reinstaled android studio?, you need regenerate the SHA1 key. Delete current key api from https://console.developers.google.com/apis/credentials and make a new key with SHA1 of new debug key store in ~/.android/debug.keystore (default password is empty).
Look this: https://www.numetriclabz.com/android-google-integration-and-login-tutorial/
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v
Paste SHA1 into new key api for debug instances.
Remember: you neeed other fingerprint of production keystore.