0

I'm using GMail API.
Currently, I ask for GET_ACCOUNTS permission and after that, I try to send some kind of a 'test' email.

If this is the user's first time, most likely UserRecoverableAuthIOException exception will be raised and I'll use its intent for asking his approval.

Is it possible to check this before trying to send and avoiding getting the exception?
Something like 'check_permission'?

SagiLow
  • 5,721
  • 9
  • 60
  • 115

1 Answers1

0

You may refer to this post regarding UserRecoverableAuthIOException: Android Drive API: getting Sys.err UserRecoverableAuthIOException if i merge code to other projects

You should catch the UserRecoverableAuthException and in the catch block, you recover the Intent from the exception by calling UserRecoverableAuthException#getIntent(). Start that intent to take user to the OAuth2 permission page for your app.

Sample code -

try {
    Drive service = Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential)
        .build();
    // Do whatever you want with the Drive service
} catch (UserRecoverableAuthIOException e) {
    startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
}
abielita
  • 13,147
  • 2
  • 17
  • 59
  • I know what to do with it once it's thrown. I want to know if the auth is given in order to avoid this from happening. – SagiLow Sep 27 '18 at 12:16