5

在开始之前,我想强调一下,我阅读了一些答案,但它们对我没有帮助。喜欢:

重复问题...

addAccountExplicitly 抛出由 Securityexception 引起的 IllegalStateException

SecurityException: caller uid XXXX is different than the authenticationator's uid ...

就像标题所暗示的那样,我试图在应用程序(不是服务)下的 Activty 中使用 AccountManager,但没有成功。我使用 4.3 模拟器(英特尔映像)。我可以轻松地列出模拟器上的所有帐户(通过 android 界面添加),但是当我想创建一个时,会出现错误:

09-14 13:21:21.863: E/AndroidRuntime(3291): java.lang.SecurityException: caller uid 10046 is different than the authenticator's uid
09-14 13:21:21.863: E/AndroidRuntime(3291):     at android.os.Parcel.readException(Parcel.java:1431)
09-14 13:21:21.863: E/AndroidRuntime(3291):     at android.os.Parcel.readException(Parcel.java:1385)
09-14 13:21:21.863: E/AndroidRuntime(3291):     at android.accounts.IAccountManager$Stub$Proxy.addAccountExplicitly(IAccountManager.java:719)
09-14 13:21:21.863: E/AndroidRuntime(3291):     at android.accounts.AccountManager.addAccountExplicitly(AccountManager.java:612)

这是我的快速代码片段:

登录.java ->

public class Login extends AccountAuthenticatorActivity {
...
    protected void onCreate(Bundle savedInstanceState) { 
    ...
        AccountManager accountmanager = AccountManager.get(this);

        Account userAccount = new Account(“Test”, “test.activities”);

        if (accountmanager.addAccountExplicitly(userAccount, “pass”, null))
        System.out.println(“Added success”);
        else System.out.println(“Added failed”);

    }
...
}

res/xml/authenticator.xml

<?xml version="1.0" encoding="utf-8"?>
<account-authenticator 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="test.activities"
    android:icon="@drawable/ic_launcher"
    android:smallIcon="@drawable/ic_launcher"
    android:label="@string/app_name"                 
/>

显现:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxxx"
    android:versionCode="1"
    android:versionName="1.0" 
    >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
    <uses-permission android:name="android.permission.USE_CREDENTIALS"></uses-permission>
    <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"></uses-permission>
    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS"></uses-permission>

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

    <application
        android:name="Application"
        android:allowBackup="true"
        android:icon="@drawable/cg_icon_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" 
      >       

        <intent-filter>
            <action android:name="android.accounts.AccountAuthenticator" />
        </intent-filter>

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

在 2.2 的安卓手机上试了一下,还是一样的错误。我可以成功列出所有帐户(使用Account[] accounts = accountmanager.getAccounts();)。我也试过这个应用程序https://play.google.com/store/apps/details?id=com.udinic.accounts_example并且可以用它添加帐户。但是通过我的申请,没有成功。

4

0 回答 0