5

There is an example of how to use Drive API https://developers.google.com/drive/quickstart-android. It works well, but I have some trouble while trying to implement uploading file to GDrive from background service.

In all examples which I found, in case when we receive UserRecoverableAuthException we need to start new Activity using Intent from that Exception (UserRecoverableAuthException#getIntent()) to take user to the OAuth2 permission page.

When we do this from Activity, we just use startActivityForResult, and as result we can use onActivityResult to know that the user finished his interaction and we can retry.

But in case, if I want to work with Drive API from Service, and there is user interaction needed, all I can do is provide Notification to user with PendingIntent. And there is no any callback for me to know when user closes OAuth2 permission page.

Can you please suggest any approach to this? Maybe I miss something? Maybe there is some broadcast I have to catch or etc?

Thank you.

abielita
  • 13,147
  • 2
  • 17
  • 59
Denys
  • 51
  • 1

1 Answers1

-2

Start an activity from the notification where you'll be handling the activity result of the permission activity. Handle the result and and optionally finish the activity.

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
  if (resultCode == Activity.RESULT_OK) {
    // permission is given
    finish();
  } else {
    or show error
  }
}
Burcu Dogan
  • 9,153
  • 4
  • 34
  • 34