AccountManager getAuthToken() throwing java.lang.IllegalArgumentException: no such account

StackOverflow https://stackoverflow.com/questions/21254144

  •  30-09-2022
  •  | 
  •  

Question

When I do the following getAuthToken() method call,

final AccountManagerFuture<Bundle> future = AccountManager.get(this)
                .getAuthToken(account, authTokenType, null, this, null, null);

it does work on the device properly, but it throws IllegalArgumentException on the emulator.

01-21 02:39:41.660: E/AndroidRuntime(1143): java.lang.IllegalArgumentException: no such account
01-21 02:39:41.660: E/AndroidRuntime(1143):     at android.os.Parcel.readException(Parcel.java:1465)
01-21 02:39:41.660: E/AndroidRuntime(1143):     at android.os.Parcel.readException(Parcel.java:1415)
01-21 02:39:41.660: E/AndroidRuntime(1143):     at android.accounts.IAccountManager$Stub$Proxy.getAuthToken(IAccountManager.java:929)
01-21 02:39:41.660: E/AndroidRuntime(1143):     at android.accounts.AccountManager$5.doWork(AccountManager.java:923)
01-21 02:39:41.660: E/AndroidRuntime(1143):     at android.accounts.AccountManager$AmsTask.start(AccountManager.java:1472)
01-21 02:39:41.660: E/AndroidRuntime(1143):     at android.accounts.AccountManager.getAuthToken(AccountManager.java:921)

I have added all required permissions in the Manifest file.

Was it helpful?

Solution

try this :

AccountManager googleAccountManager = AccountManager.get(this);
final Account[] accounts = googleAccountManager.getAccountsByType("com.google");

This will give you array of google accounts on the device

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top