Android帐户身份验证器:在首选项屏幕中区分帐户

时间:2013-09-10 13:33:17

标签: android authentication account

我的帐户身份验证工具就像一个魅力,它的xml看起来或多或少:

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="lorenzoff_account"
    android:icon="@drawable/nice_icon"
    android:smallIcon="@drawable/nice_icon"
    android:label="@string/app_name" 
    android:accountPreferences="@xml/account_preferences" />

通过此身份验证器可以管理多个帐户,我们假设account_A,account_B。 一旦定义了两个帐户,访问帐户&amp;同步设置并单击其中一个将打开相对account_preferences屏幕。 它的xml或多或少看起来像这样:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
   <PreferenceCategory android:title="@string/title_fmt" />
   <PreferenceScreen
        android:key="key1"
        android:title="click me"
        android:summary="dont be afraid, click!">
        <intent
            android:action="com.lorenzoff.authenticator.ACTION_UNKNOWN"
            android:targetPackage="key1.package"
            android:targetClass="key1.class" />
    </PreferenceScreen>
</PreferenceScreen>

我的问题是我无法弄清楚如何区分意图接收类中的两个帐户。如果我单击account_A或account_B,则在两种情况下接收类都会正确接收com.lorenzoff.authenticator.ACTION_UNKNOWN操作,但如何确定是否单击了accout_A或account_B?

1 个答案:

答案 0 :(得分:0)

一些实验表明,标准Android设置应用程序通过启动"account"活动的Intent随附的附加软件包中的密钥android:accountPreferences传递目标帐户。

不幸的是,我似乎也看不到任何证明这是否总是正确的文件;如果有人能证明不是这样的话会很棒。