【问题标题】:Show settings under accounts & sync menu for android app在 Android 应用的帐户和同步菜单下显示设置
【发布时间】:2012-05-26 08:44:51
【问题描述】:

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

【问题讨论】:

    标签: android android-syncadapter accounts


    【解决方案1】:

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

    【讨论】:

    • 这个老qsn!但是 Intent intent=new Intent(Settings.ACTION_SYNC_SETTINGS); //ACTION_SETTINGS startActivity(intent); 不启动首选项屏幕!!
    【解决方案2】:

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

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

    希望这会有所帮助...

    【讨论】:

    • 不,这不是我想要做的(尽管很高兴知道这一点)。我正在尝试在.accounts 菜单下添加“常规设置”,如上图所示
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 2013-07-22
    • 1970-01-01
    相关资源
    最近更新 更多