0

我的帐户验证器就像一个魅力,它的 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。一旦定义了两个帐户,访问 Account & Sync 设置并单击其中一个会打开相关的 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?

4

1 回答 1

1

一些实验表明,标准的 Android 设置应用程序通过启动Activity"account"的 Intent 附带的 extras Bundle 中的密钥传递目标帐户。android:accountPreferences

不幸的是,我似乎也看不到任何文件可以保证这是否总是正确的;如果有人可以证明并非如此,那就太好了。

于 2014-02-05T01:57:17.807 回答