This seems to be a basic feature but after following the signing-in tutorial, it only works if I choose the account that is already registered on the device.
After choosing 'Use another account' and completing some steps to authenticate it looses the call-back result, (onActivityResult is not called).
I use GoogleSignInOptions: no exception occurs and I can't add any listener to detect exceptions.
However, GoogleApiClient works fine but there are some deprecated methods, thus I decided to switch to GoogleSignInOptions to avoid deprecation issues.
Initizlization:
googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
googleSignInClient = GoogleSignIn.getClient(this, googleSignInOptions);
when click:
signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signIn();
}
});
private void signIn() {
googleSignInClient.signOut();
Intent signInIntent = googleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, 123);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 123 && data != null) {
handleSignInResult(data);
}
}
private void handleSignInResult(Intent data) {
Task<GoogleSignInAccount> signInTask = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
GoogleSignInAccount googleSignInAccount = signInTask.getResult(ApiException.class);
if (googleSignInAccount != null) {
updateUI(googleSignInAccount);
}
} catch (ApiException e) {
e.printStackTrace();
}
}
Anyone can help please?
