-
-
Save imminent/76cdc9750236bb269e168cc7c31df3cd to your computer and use it in GitHub Desktop.
Smart Lock Hint Request for Smarter Signup with Smart Lock for Android blog post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final int SMART_LOCK_SIGNIN_REQUEST = 1003; | |
// Request credentials | |
if (mGoogleApiClient.isConnected()) { | |
showProgressDialog(R.string.please_wait); | |
HintRequest hintRequest = new HintRequest.Builder() | |
.setHintPickerConfig(new CredentialPickerConfig.Builder() | |
setShowCancelButton(true) | |
.build()) | |
// Give us email addresses | |
.setEmailAddressIdentifierSupported(true) | |
// Give us Google accounts | |
.setAccountTypes(IdentityProviders.GOOGLE) | |
.build(); | |
PendingIntent intent = | |
Auth.CredentialsApi.getHintPickerIntent(mGoogleApiClient, | |
hintRequest); | |
try { | |
startIntentSenderForResult(intent.getIntentSender(), | |
SMART_LOCK_SIGNIN_REQUEST, null, 0, 0, 0); | |
} catch (IntentSender.SendIntentException e) { | |
// Log error | |
} | |
} | |
// Receive result | |
switch (requestCode) { | |
case SMART_LOCK_SIGNIN_REQUEST: | |
if (resultCode == Activity.RESULT_OK) { | |
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY); | |
handleSmartLockCredentials(credential); | |
} else if (resultCode == CredentialsApi.ACTIVITY_RESULT_OTHER_ACCOUNT) { | |
// User tapped "NONE OF THE ABOVE", let them do the manual login flow | |
goToStandardLoginActivity(); | |
} else { | |
// User canceled the Smart Lock dialog | |
} | |
break; | |
} | |
// Handle result | |
private void handleSmartLockCredentials(final Credential credential) { | |
showProgressDialog(R.string.plus_logging_in); | |
String accountType = credential.getAccountType() == null ? | |
"" : credential.getAccountType(); | |
switch (accountType) { | |
case IdentityProviders.GOOGLE: | |
List<com.google.android.gms.auth.api.credentials.IdToken> idTokens = | |
credential.getIdTokens(); | |
if (idTokens != null && !idTokens.isEmpty()) { | |
String name = credential.getName(); | |
mLoginPresenter.signInWithSmartLock(idTokens.get(0).getIdToken(), name); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment