0

Hi i am trying to get an existing account i've recently created using:

 AccountManager am = AccountManager.get(activity);
        Account[] acc = am.getAccountsByType( activity.getResources().getString(R.string.ACCOUNT_TYPE));

and my manifest

on="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.test.sample"
        >

    <!--<uses-permission android:name="android.permission.GET_ACCOUNTS" />-->
    <!-- Request permission to use a device camera -->
    <uses-permission android:name="android.permission.CAMERA"/>

    <uses-feature android:name="android.hardware.camera2"/>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
    <uses-permission android:name="android.permission.READ_SYNC_STATS" />

    <uses-permission android:name="android.permission.READ_CALENDAR"/>
    <uses-permission android:name="android.permission.WRITE_CALENDAR"/>
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />

    <!-- client -->
    <uses-permission android:name="android.permission.USE_CREDENTIALS"/>
    <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>

    <!-- Authenticator -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>

    <application
           ...

        <service
            android:name="com.test.sample.AccountAuthenticatorService"
            android:exported="true" android:process=":auth"
            >
            <intent-filter>
                <action android:name="android.accounts.AccountAuthenticator" />
            </intent-filter>

            <meta-data
                android:name="android.accounts.AccountAuthenticator"
                android:resource="@xml/authenticator" />
        </service>

    </application>

</manifest>

getAccountsByType required GET_ACCOUNTS permission which I already added into manifest but still I get this error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.sample/com.test.sample.activities.MainActivity}: java.lang.SecurityException: caller uid 10340 lacks any of android.permission.GET_ACCOUNTS

I googled to this:

Permissions Not Working

but still getting the same error. This error only happens on android devices(multiple samsung devices) but was fine in emulators.

Anyone knows any other solutions that might work?

Community
  • 1
  • 1
  • Try cleaning your project and uninstall the app on the device and re-install. Also did you make sure to increment the version number so you could please it? Another way would be to use 'adb install -r ' – JoxTraex Aug 13 '15 at 03:12
  • Thanks for your reply. Tried clear, uninstall and also delete all accounts. resync gradle, clean project and install to device and still having the same error. – Wong Soong Wei Aug 13 '15 at 03:49
  • Ive been stuck for 2 days at this problem. I am thinking of saving the account object into my separate db. This as an bypass solution. – Wong Soong Wei Aug 13 '15 at 03:50
  • Check the manifest being pushed to the app (inside of your bin directory) and ensure it has the permission. Also have you validated that your are pushing the right APK to your device? – JoxTraex Aug 13 '15 at 06:10
  • hi jox, i've checked the permission in settings> app and I do see the add/remove/read account in there but the error still persist. I could wait any longer so I saved the account in DB instead. I know this is not a solution :( – Wong Soong Wei Aug 17 '15 at 08:40
  • I got the same error too. Do you have any solutions now? – Allen Vork Feb 09 '17 at 07:48

0 Answers0