【问题标题】:android sync adapter Security Exceptionandroid 同步适配器安全异常
【发布时间】:2018-06-27 07:53:12
【问题描述】:

错误

原因:java.lang.SecurityException: uid 10184 cannot get secrets 对于以下类型的帐户:

代码

    @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;
}

身份验证器服务

    <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>

【问题讨论】:

  • 请添加一些解释,您要达到什么目的以及问题所在。

标签: android android-syncadapter securityexception


【解决方案1】:

添加

<uses-permission android:name="Manifest.permission.GET_ACCOUNTS"/>

到你的Manifest应该解决你的SecurityException

(从 Android 6.0(API 级别 23)开始,如果应用共享管理帐户的身份验证器的签名,则无需“GET_ACCOUNTS”权限即可读取有关该帐户的信息。在 Android 5.1 及更低版本上,所有应用需要“GET_ACCOUNTS”权限才能读取任何帐户的信息。)

【讨论】:

    猜你喜欢
    • 2013-11-24
    • 2016-01-08
    • 2012-01-13
    • 2012-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-04
    相关资源
    最近更新 更多