Java – Calling any AccountManager getAccounts stops my application

Calling any AccountManager getAccounts stops my application… here is a solution to the problem.

Calling any AccountManager getAccounts stops my application

This code reproduces the issue and that’s it. Just take an activity and create an AccountManger instance, then call getAccounts(), it never reaches the for(... line.

public class MainActivity extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
        AccountManager manager = AccountManager.get(this);
        Account[] accounts = manager.getAccounts();
        for (int index = 0 ; index < accounts.length ; ++index)
            Log.i("RumbAPK", accounts[index].name);

All I want to do is be able to list the current account and check if it is authenticated to use it as an authentication system for my application.


According to @ CommonsWave is of course required because it has to be useful.

java.lang.SecurityException: caller uid 10085 lacks any of android.permission.GET_ACCOUNTS
    at android.os.Parcel.readException(
    at android.os.Parcel.readException(
    at android.accounts.IAccountManager$Stub$Proxy.getAccountsAsUser(
    at android.accounts.AccountManager.getAccountsByTypeAsUser(
    at android.accounts.AccountManager.getAccountsByType(
    at android.view.View.performClick(
    at android.view.View$
    at android.os.Handler.handleCallback(
    at android.os.Handler.dispatchMessage(
    at android.os.Looper.loop(
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(
    at dalvik.system.NativeStart.main(Native Method)


Based on the stack trace, I’m pretty sure you’re missing GET_ACCOUNTS permissions in AndroidManifest.xml

Please add this line:

<pre class=”lang-none prettyprint-override”><uses-permission android:name="android.permission.GET_ACCOUNTS"/>

.xml to AndroidManifest

Read moreInformations about the permission system on Android.

Related Problems and Solutions