I followed the google quick launch example to configure the GMail API: https://developers.google.com/gmail/api/quickstart/android
My application successfully requests GET_ACCOUNTS permission and allows the user to select their gmail account. The selected account is stored in SharedPreferences for later access.
Through IntentService, my application sends an email. I followed the instructions located here: https://developers.google.com/gmail/api/guides/sending and included the activ.jar, Additional.jar and mail.jar libraries as needed. When I send an email with the code below, I get a UserRecoverableAuthUIException :
message = service.users().messages().send(userId, message).execute();
When I catch the exception, get the intent saved with the exception, and start the intent as a new action. I am shown a dialog giving me the ability to allow my application to send email with my GMail account:

After clicking "Allow" in this dialog box, my application sends emails without any additional problems. My application also appears on my Google Account Permissions page on the Internet, which says it has permission to send email.
Is there a way to manually run this dialog box when I first get the user account name and not expect an exception to occur?
UPDATE
I managed to extract the action and data stored in the intent, if that helps:
- action: com.google.android.gms.ui.UNPACKING_REDIRECT
- data: target: //com.google.android.gms.auth.uiflows.common/KEY
where KEY is a series of characters, possibly associated with my account or being a token.
EDIT:
Below is the code to create the Credentials object and start the account that I am using:
private GoogleAccountCredential mCredential; private static final String[] SCOPES = { GmailScopes.GMAIL_COMPOSE };
Internal constructor:
mCredential = GoogleAccountCredential.usingOAuth2( getApplicationContext(), Arrays.asList(SCOPES)) .setBackOff(new ExponentialBackOff());
Where do I get the account:
private void chooseGMailAccount() { String accountName = this.getSharedPreferences(getString(R.string.shared_pref_main), Context.MODE_PRIVATE) .getString(getString(R.string.srd_pref_gmail_account), null); if (accountName != null) { mCredential.setSelectedAccountName(accountName); configureGMailAPI(); } else { startActivityForResult( mCredential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER); } }