Search code examples
androidaccountmanagergoogle-play-services

Is it possible to let the user authorize permissions in app instead when using AccountManager


I use AccountManager to get access token to authorize calls to Google Drive. When running this line of code:

mgr.blockingGetAuthToken(account, ApiConst.DRIVE_AUTH_SCOPE, true);

The user gets a notification whith permission requests. Is it possible to show this from the app and let the user accept the permissions? I know that if using Google Play Service i can catch an exception and extract an intent to use:

  try {
    return GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
  } catch (UserRecoverableAuthException userRecoverableException) {
    mActivity.startActivityForResult(userRecoverableException.getIntent(), mRequestCode);
  }

Is there a similar way to achieve this when using AccountManager?


Solution

  • Solved it. If I use this method the user will be asked to accept permissions instead of getting a notification:

        am.getAuthToken (
                account.account,
                ApiConst.DRIVE_AUTH_SCOPE,
                options,
                this,
                new OnTokenAcquired(),
                null);
    

    OnTokenAcquired is a class implementing AccountManagerCallback. In its run method you will get the token.