14

Androidアプリ用の同期アダプターを実装していますが、[アカウントと同期]メニューでアカウントの設定を利用できるようにしたいと思います。DropBoxアプリでこれが行われるのを見ましたが(以下に示すように)、これを行う方法に関するドキュメントを見つけることができませんでした。アカウントを追加しました。このメニューのアカウント設定へのリンクを追加したいだけです。

ここに画像の説明を入力してください

4

2 に答える 2

23

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>

上記の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 に答える