Java 将应用程序移动到SD卡时帐户身份验证器丢失
当我将testapp移动到SD卡时,我的自定义帐户验证器(com.heidi.AccountStuff)不再存在 如果我想添加一个像这样的新帐户Java 将应用程序移动到SD卡时帐户身份验证器丢失,java,android,Java,Android,当我将testapp移动到SD卡时,我的自定义帐户验证器(com.heidi.AccountStuff)不再存在 如果我想添加一个像这样的新帐户 Account account = new Account("heidi", AccountAuthenticatorService.TYPE); AccountManager accountManager = AccountManager.get(this); accountManager.addAccountExplicitly(account,
Account account = new Account("heidi", AccountAuthenticatorService.TYPE);
AccountManager accountManager = AccountManager.get(this);
accountManager.addAccountExplicitly(account, "", null);
它将引发RuntimeException
java.lang.SecurityException: caller uid XXXXX is different than the authenticator's uid
好的,有意义,因为当我输出authenticatortypes(带有以下代码段)时:
它将输出
AuthenticatorDescription {type=com.htc.linkedin}
AuthenticatorDescription {type=com.htc.android.mail.eas}
AuthenticatorDescription {type=com.htc.sync.provider.weather}
AuthenticatorDescription {type=com.htc.android.windowslive}
AuthenticatorDescription {type=com.htc.android.mail}
AuthenticatorDescription {type=com.htc.stock}
AuthenticatorDescription {type=com.htc.lucy.account}
AuthenticatorDescription {type=com.google}
将应用程序移回内部存储后,我的自定义类型将显示在输出中,如下所示:
AuthenticatorDescription {type=com.heidi.AccountStuff}
AuthenticatorDescription {type=com.htc.linkedin}
AuthenticatorDescription {type=com.htc.android.mail.eas}
AuthenticatorDescription {type=com.htc.sync.provider.weather}
AuthenticatorDescription {type=com.htc.android.windowslive}
AuthenticatorDescription {type=com.htc.android.mail}
AuthenticatorDescription {type=com.htc.stock}
AuthenticatorDescription {type=com.htc.lucy.account}
AuthenticatorDescription {type=com.google}
有什么想法吗?实现自定义帐户的部分很少 要在活动中调用AccountManager,您已经实现了类似的功能
Account account = new Account(username, ACCESS_TYPE);
AccountManager am = AccountManager.get(this);
Bundle userdata = new Bundle();
userdata.putString("SERVER", "extra");
if (am.addAccountExplicitly(account, password, userdata)) {
Bundle result = new Bundle();
result.putString(AccountManager.KEY_ACCOUNT_NAME, username);
result.putString(AccountManager.KEY_ACCOUNT_TYPE, ACCESS_TYPE);
setAccountAuthenticatorResult(result);
}
在res/xml/authenticator.xml中,必须定义AccountAuthenticator数据(负责验证器UID)。访问类型必须与此xml中定义的accountType相同
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="de.buecherkiste"
android:icon="@drawable/buecher"
android:label="@string/app_name"
android:smallIcon="@drawable/buecher" >
</account-authenticator>
最后,您必须定义您的服务和清单。请不要忘记管理您的帐户的相关权限(验证\u帐户/使用\u凭据/获取\u帐户/管理\u帐户)
检查以下链接:&打印sd卡和本地存储的uid值/帐户名+密码。我认为在将应用程序从本地移动到sd时,它会被视为一个不同的应用程序&我希望它对你有用:)谢谢你的回答,但是你回答的所有PAR都已经实现了,问题只在于应用程序安装在sd卡上。
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="de.buecherkiste"
android:icon="@drawable/buecher"
android:label="@string/app_name"
android:smallIcon="@drawable/buecher" >
</account-authenticator>
<service android:name="AuthenticatationService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>