Recently, I have Android code which accesses to Google Drive. I\'m using Google APIs Client Library for Java instead of Google Play services client
I use google api client
// Dependency of Google Api client
implementation 'com.google.api-client:google-api-client:1.30.9'
implementation 'com.google.api-client:google-api-client-android:1.30.9'
implementation 'com.google.apis:google-api-services-drive:v3-rev20200413-1.30.9'
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(Scopes.DRIVE_APPFOLDER))
//requestEmail required
.requestEmail()
.build();
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
// in onActivityResult method
Task task = GoogleSignIn.getSignedInAccountFromIntent(data);
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
// androidAccount will be null if no email
android.accounts.Account androidAccount = account.getAccount();
You can see it from the source code of android.accounts.Account
private String zag;
@Field(
id = 4,
getter = "getEmail"
)
private String zah;
@Nullable
public Account getAccount() {
// getEmail required
return this.zah == null ? null : new Account(this.zah, "com.google");
}