Skip to content

Instantly share code, notes, and snippets.

@yccheok
Created December 16, 2024 01:58
Show Gist options
  • Save yccheok/d2f16a7807ee6cf73347153a4a8ebb53 to your computer and use it in GitHub Desktop.
Save yccheok/d2f16a7807ee6cf73347153a4a8ebb53 to your computer and use it in GitHub Desktop.
private void xxx() {
Log.i("CHEOK", "xxx");
GetGoogleIdOption googleIdOption = new GetGoogleIdOption.Builder()
.setFilterByAuthorizedAccounts(true)
.setAutoSelectEnabled(true)
.setServerClientId(Constants.WENOTE_CLOUD_STORAGE_CLIENT_ID)
.setNonce("NONCE")
.build();
androidx.credentials.GetCredentialRequest request = new androidx.credentials.GetCredentialRequest.Builder()
.addCredentialOption(googleIdOption)
.build();
Context context = getContext();
CredentialManager credentialManager = CredentialManager.create(context);
credentialManager.getCredentialAsync(
context,
request,
null, // pass in a CancelationSignal to allow cancelling the request
Runnable::run, // Execute the callback immediately
new CredentialManagerCallback<GetCredentialResponse, GetCredentialException>() {
@Override
public void onResult(@NonNull GetCredentialResponse result) {
android.util.Log.i("CHEOK", "onResult " + result);
if (result != null) {
GoogleIdTokenCredential credential = (GoogleIdTokenCredential) result.getCredential();
android.util.Log.i("CHEOK", credential.getId());
android.util.Log.i("CHEOK", credential.getDisplayName());
} else {
android.util.Log.i("CHEOK", "ERROR!!!");
}
}
@Override
public void onError(@NonNull GetCredentialException e) {
android.util.Log.i("CHEOK", "onError " + e);
}
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment