How to get your Google Drive account name
I am using the Google Drive API for a CRUD file. Everything works fine, but I can't get the Google Drive account name in the onActivityResult () method. My code looks like this:
In onCreate()
:
String[] accountTypes = new String[]{"com.google"};
Intent intent = AccountPicker.newChooseAccountIntent(null, null,
accountTypes, false, null, null, null, null);
startActivityForResult(intent, REQ_AUTH);
In onAcivityResult()
:
protected void onActivityResult(final int rqst, final int rslt,
final Intent data) {
if ((rqst == REQ_AUTH) && (rslt == Activity.RESULT_OK)) {
accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
if (accountName != null) {
googleApiClient.init(UploadFileOnGoogleDrive.this, accountName)
.connect();
}
}
It data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME)
always comes back here null
. I also put a condition like d ata!=null && data.getStringExtras()!=null
, but the condition will never be met. Please help me.
+3
source to share
No one has answered this question yet
See similar questions:
or similar: