Reputation: 41
Error
Caused by: java.lang.SecurityException: uid 10184 cannot get secrets for accounts of type:
Code
@Nullable
public static Account getSyncAccount(Context context)
{
AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
Account newAccount = new Account(context.getString(R.string.app_name), context.getString(R.string.content_authority));
assert accountManager != null;
if(null == accountManager.getPassword(newAccount))
{
if(!accountManager.addAccountExplicitly(newAccount,"",null)) //Error here
{
return null;
}
onAccountCreated(newAccount,context);
}
return newAccount;
}
Authenticator Service
<service android:name=".sync.ProductAuthenticatorService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/>
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator"/>
</service>
<!-- Sync Adapter Service -->
<service android:name=".sync.ProductSyncService"
android:exported="true"
>
<intent-filter>
<action android:name="android.content.SyncAdapter"/>
</intent-filter>
<meta-data android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter"/>
</service>
Upvotes: 1
Views: 290
Reputation: 1208
Adding
<uses-permission android:name="Manifest.permission.GET_ACCOUNTS"/>
To your Manifest should solve your SecurityException
.
(Beginning with Android 6.0 (API level 23), if an app shares the signature of the authenticator that manages an account, it does not need "GET_ACCOUNTS" permission to read information about that account. On Android 5.1 and lower, all apps need "GET_ACCOUNTS" permission to read information about any account.)
Upvotes: 1