Created
December 16, 2024 01:58
-
-
Save yccheok/d2f16a7807ee6cf73347153a4a8ebb53 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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