I set up the authorization process for Google Play Services as described under https://developers.google.com/drive/android/auth
Now that the user has authorized the app I want to retrieve the account name. But I can't find any method in the API (http://developer.android.com/reference/gms-packages.html) that would be helpful.
Looks like data Intent is always null :(
This code is from ConnectionResult.class
Check if user signed or not
If you want to get email and name after signing in
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case REQUEST_CODE_DRIVE_SIGN_IN: Log.i(TAG, "Sign in request code"); // Called after user is signed in. if (resultCode == RESULT_OK) { Log.i(TAG, "Signed in successfully."); // Use the last signed in account here since it already have a Drive scope. GoogleSignInAccount googleSignInAccount = GoogleSignIn.getLastSignedInAccount(this); googleSignInAccount.getEmail(); mDriveClient = Drive.getDriveClient(this, GoogleSignIn.getLastSignedInAccount(this)); // Build a drive resource client. mDriveResourceClient = Drive.getDriveResourceClient(this, GoogleSignIn.getLastSignedInAccount(this)); } break;}}
The details could be found here
I assume that you already have QUICKSTART or DEMO, or something similar up-and-running, so I will refer to these 2 examples. In the BaseDemoActivity.java code, you'll notice that account selection is invoked when connection fails,
... and it comes back in onActivityResult(). I just grab the intent data and get the KEY_ACCOUNT_NAME, it is the selected email. The code below is modified from the DEMO's BaseDemoActivity.java (I mentioned above).
Hope it helps.