2012-04-24 27 views
6

我正在試驗Android AccountManagerSecurityException在嘗試添加帳戶時

我有一個帳戶驗證服務,顯示用戶界面輸入用戶名/密碼。

我轉到設置/帳戶/添加帳戶,選擇我的新帳戶類型,我與用戶界面呈現。

當我點擊OK我收到以下錯誤

04-24 14:48:29.334: E/AndroidRuntime(386): java.lang.SecurityException: 
    caller uid 10035 is different than the authenticator's uid 

MyAccountAuthenticationService的唯一方法:

@Override 
public IBinder onBind(Intent intent) { 
    return new MyAccountAuthenticator(this).getIBinder(); 
} 

MyAccountAuthenticator:

MyAccountCreatorActivity的的
@Override 
public Bundle addAccount(AccountAuthenticatorResponse response, 
    String accountType, String authTokenType, String[] requiredFeatures, 
    Bundle options) throws NetworkErrorException { 

    final Intent intent = new Intent(context, MyAccountCreatorActivity.class); 
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); 
    final Bundle bundle = new Bundle(); 
    bundle.putParcelable(AccountManager.KEY_INTENT, intent); 
    return bundle; 
} 

片段onClick

AccountManager accManager = AccountManager.get(this); 
Account newAccount = new Account(email, MyAccountAuthenticator.ACCOUNT_TYPE); 
accManager.setPassword(newAccount, password); 

例外情況引發setPassword。我已經要求所有的會計許可。我不確定可能會造成這種情況。如果您需要更多的代碼/信息,請詢問。

謝謝。

+2

看到這個http://loganandandy.tumblr.com/post/613041897/caller-uid-is-different也許有幫助 – 2012-04-24 15:09:35

+0

可能重複的[SecurityException:調用者uid XXXX是不同於認證者的uid](http:// stackoverflow.com/questions/3774282/securityexception-caller-uid-xxxx-is-different-than-the-authenticators-uid) – rds 2015-10-27 18:34:40

+0

@rds對不起,這不是一個騙局。原來的XML有一個錯字,但是Android並不能解釋你問題的真正本質 – 2015-10-28 07:37:45

回答

4

感謝@imran汗,我發現我的恆定值不匹配「正是」什麼是認證XML定義

+0

我不明白你的「驗證器XML定義」與關於AndroidManifest的回答有什麼不同。您是否需要與您的AndroidManifest相匹配或者是否在其他地方提供了答案? – Danny 2013-08-15 17:24:31

+0

如果我將org.zighinetto.myapp.account輸入爲org.zighinetto.myap.account,它將不起作用。它只是在XML中定義的一種方式,在代碼中另一種方式(公共靜態最終字符串......你知道......) – 2013-08-20 11:58:36

+0

有道理。謝謝! – Danny 2013-08-20 17:38:55

17

似乎是顯而易見的,但你也將看到此錯誤,如果您的認證服務有沒有已在AndroidManifest.xml中定義。例如:

<service android:name="your.AuthService"> 
    <intent-filter> 
     <action android:name="android.accounts.AccountAuthenticator" /> 
    </intent-filter> 
    <meta-data android:name="android.accounts.AccountAuthenticator" 
     android:resource="@xml/authenticator" /> 
</service> 
+0

感謝您的回答。這個問題並沒有說我已經寫了XML,在這種情況下,語法故障 – 2013-06-07 06:53:49

1

在我來說,我不小心在清單中定義AuthenticatorService的<application>標籤之外。移動<application>內的聲明解決了問題。希望會幫助別人。

3

就我而言,當我在同一臺設備上運行兩種不同風味時,出現此錯誤。第二個是試圖訪問第一個相同的帳戶,這導致了錯誤。

+0

我在Android 5手機上遇到了同樣的問題,我通過更改flavor維度名稱來解決這個問題,這要感謝您的回答:) – matdev 2017-12-14 10:46:04