我正在为Android应用程序实现一个Syncapapter,并希望为“帐户和同步”菜单下的可用帐户进行设置。我在Dropbox App中看到了这一点(如下所示),但我没有能够找到关于如何执行此操作的文档。我有帐户添加了,只想在此菜单中添加到帐户设置的链接。

有帮助吗?

解决方案

在您的Android清单中,您应该有一个如此可以定义您的帐户身份验证器:

<service android:name="AccountAuthenticatorService"
 android:exported="true" android:process=":auth">
 <intent-filter>
  <action android:name="android.accounts.AccountAuthenticator" />
 </intent-filter>
 <meta-data android:name="android.accounts.AccountAuthenticator"
  android:resource="@xml/authenticator" />
</service>
.

上面的元数据标记应该指向定义您帐户的XML文件,如下所示:

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="fm.last.android.account"
    android:icon="@drawable/icon"
    android:smallIcon="@drawable/icon"
    android:label="@string/app_name"
    android:accountPreferences="@xml/account_preferences"/>
.

android:accountpreferences属性上面的点到定义首选项屏幕的XML文件,如:

<PreferenceScreen
  xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory
            android:title="General Settings" />

    <PreferenceScreen
        android:key="account_settings"
        android:title="Account Settings"
        android:summary="Sync frequency, notifications, etc.">
        <intent
            android:action="fm.last.android.activity.Preferences.ACCOUNT_SETUP"
            android:targetPackage="fm.last.android"
            android:targetClass="fm.last.android.activity.Preferences" />
    </PreferenceScreen>
</PreferenceScreen>
.

上面的首选项屏幕将启动意图显示设置屏幕,但您也可以直接在XML文件中定义设置。

其他提示

如果我正确地理解,您希望从应用程序中显示“帐户和同步设置”屏幕。为此,您必须触发意图进行设置。使用下面给出的代码:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.android.providers.subscribedfeeds","com.android.settings.ManageAccountsSettings"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
.

希望这有助于...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top