在帐户和帐户下显示设置Android应用程序的同步菜单

时间:2012-05-18 19:00:40

标签: android android-syncadapter accounts

我正在为Android应用程序实现一个syncadapter,并希望在“帐户和同步”菜单下对该帐户进行设置。我已经在DropBox应用程序中看到了这一点(如下所示),但我无法找到有关如何执行此操作的文档。我添加了帐户,只想在此菜单中添加指向帐户设置的链接。

enter image description here

2 个答案:

答案 0 :(得分:22)

在您的Android Manifest中,您应该有一个这样的部分来定义您的帐户身份验证器:

<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>

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

答案 1 :(得分:0)

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

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);

希望这有助于......