在帐户和下显示设置Android 应用程序的同步菜单 [英] Show settings under accounts & sync menu for android app

查看:27
本文介绍了在帐户和下显示设置Android 应用程序的同步菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Android 应用实现同步适配器,并希望在帐户与同步"菜单下提供帐户设置.我已经在 DropBox 应用程序中看到了这一点(如下所示),但我无法找到有关如何执行此操作的文档.我已经添加了账号,只是想在这个菜单中添加一个到账号设置的链接.

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.

推荐答案

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

In your Android Manifest, you should have a section like this to define your account authenticator:

<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 文件,像这样:

The meta-data tag above should point to an XML file that defines your account, like this:

<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 文件,如下所示:

The android:accountPreferences attribute above points to an XML file that defines your preferences screen, like so:

<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 文件中定义设置.

The above PreferenceScreen will launch an intent to display a settings screen, but you can also define the settings directly in the XML file.

这篇关于在帐户和下显示设置Android 应用程序的同步菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆