Android AccountManager API

I am trying to understand the Android AccountManager API. As I understand it, I can use the blockingGetAuthToken method and indicate whether Android should provide a notification to the user that allows or rejects the request. Another possibility is to use getAuthToken and check if KEY_INTENT is returned. If in this case I could start a new action in which the user can confirm my request.

My problem is that I would like to call one of these two methods from the Service. Is there a chance to get a callback after the user has made a decision?

thanks for the help

+3
source share
1 answer

, , , :

AccountManager mgr = AccountManager.get(getApplicationContext());
Account[] accounts = mgr.getAccountsByType("com.mydomain");
// assert that accounts is not empty

AccountManagerFuture<Bundle> . , Android :

private AccountManagerFuture<Bundle> myFuture = null;
private AccountManagerCallback<Bundle> myCallback = new AccountManagerCallback<Bundle>() {
    @Override public void run(final AccountManagerFuture<Bundle> arg0) {
        try {
           myFuture.getResult().get(AccountManager.KEY_AUTHTOKEN); // this is your auth token
       } catch (Exception e) {
           // handle error
       }
   }

}

:

myFuture = mgr.getAuthToken(accounts[0], AUTH_TOKEN_TYPE, true, myCallback, null);
+3

Source: https://habr.com/ru/post/1745730/


All Articles