我有一个帐户类型“mypackage.account”和一个内容授权“mypackage”。我有一个Service
提供 的实现AbstractAccountAuthenticator
,addAccount
方法是这样实现的:
/**
* The user has requested to add a new account to the system. We return an intent that will launch our login
* screen if the user has not logged in yet, otherwise our activity will just pass the user's credentials on to
* the account manager.
*/
@Override
public Bundle addAccount(AccountAuthenticatorResponse response, String account_type, String auth_token_type,
String[] required_features, Bundle options) throws NetworkErrorException {
final Intent intent = new Intent(_context, ConnectAccountActivity.class);
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
final Bundle reply = new Bundle();
reply.putParcelable(AccountManager.KEY_INTENT, intent);
return reply;
}
我提供一个authenticator.xml
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="mypackage.account"
android:icon="@drawable/ic_launcher"
android:smallIcon="@drawable/ic_launcher"
android:label="@string/app_name"
android:accountPreferences="@xml/account_preferences" />
我这样Service
定义AndroidManifest.xml
:
<!-- Account authentication service that provides the methods for authenticating KeepandShare accounts to the
AccountManager framework -->
<service android:exported="true" android:name=".authenticator.AccountAuthenticatorService" android:process=":auth" tools:ignore="ExportedService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/>
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator"/>
</service>
这就是设置,现在当我想在设备上显示一个包含我的帐户类型帐户列表的屏幕以及添加新帐户的操作时,我的添加帐户操作如下所示:
final Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[]{ "mypackage" });
startActivity(intent);
在这一点上,我被引导到一个帐户类型选择器,其中显示“mypackage.account”和“anotherpackage.account”作为选项。(“anotherpackage.account”在我工作的另一个应用程序中定义)这似乎不像预期的行为。我已经检查了大约 20 次,两个应用程序定义的权限是不同的——而且确实如此。有人可以告诉我我缺少什么吗?