14

I am implementing a syncadapter for an android app and would like to make the settings for the account available under the "Accounts & sync" menu. I have seen this done in the DropBox app(as shown below), but I have not been able to find documentation on how to do this. I have the accounted added, just want to add a link to the account settings in this menu.

enter image description here

4

2 回答 2

23

在您的 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 文件中定义设置。

于 2012-05-20T18:58:52.907 回答
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);

希望这有帮助...

于 2012-05-18T20:16:52.807 回答