我正在尝试使用Android AccountManager.
我有一个帐户身份验证服务,显示用于输入用户名/密码的UI.
我转到设置/帐户/添加帐户,选择我的新帐户类型,然后我看到了UI.
当我单击确定时,我收到以下错误
04-24 14:48:29.334: E/AndroidRuntime(386): java.lang.SecurityException:
caller uid 10035 is different than the authenticator's uid
Run Code Online (Sandbox Code Playgroud)
MyAccountAuthenticationService的唯一方法:
@Override
public IBinder onBind(Intent intent) {
return new MyAccountAuthenticator(this).getIBinder();
}
Run Code Online (Sandbox Code Playgroud)
MyAccountAuthenticator:
@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;
}
Run Code Online (Sandbox Code Playgroud)
片段MyAccountCreatorActivity的onClick
AccountManager accManager = AccountManager.get(this);
Account newAccount = new Account(email, …Run Code Online (Sandbox Code Playgroud) 在我开始之前,我想强调一下,我读了一些答案但他们并没有帮助我.喜欢:
addAccountExplicitly抛出Securityexception引起的IllegalStateException
SecurityException:调用者uid XXXX与身份验证者的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)
Run Code Online (Sandbox Code Playgroud)
这是我的快速代码片段:
Login.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”);
}
...
}
Run Code Online (Sandbox Code Playgroud)
RES/XML/authenticator.xml …
我想明确地添加一个谷歌帐户.我会提供用户名和密码.
我刚刚通过这个问题调用者uid XXXX与验证者的uid不同 但我没有得到解决方案.什么是uid?你比较的是哪个.
我在尝试
AccountManager mgr = (AccountManager)getSystemService(ACCOUNT_SERVICE);
Account acc = new Account("xxxj@gmail.com", "com.google");
if(mgr.addAccountExplicitly(acc, "Password", new Bundle()))
{
//account added successfully
//do whatever is needed;
showToast("added");
}
else {
//something did not work
}
Run Code Online (Sandbox Code Playgroud)
错误:调用者uid 10782与身份验证者的uid不同.
这是什么意思?我该如何纠正呢?
任何人请告诉我如何解决这个完整的代码将是非常有帮助的.