问题
My account authenticator works like a charm and its xml looks more or less this way:
<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" />
By this authenticator is it possible to manage more then one account, lets suppose account_A, account_B. Once defined the two accounts, accessing the Account & Sync settings and clicking one of them opens the relative account_preferences screen. Its xml looks more or less this way:
<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>
My problem is that I cannot figure out how to distinguish between the two accounts in the intent receiving class. If I click account_A or account_B, in both cases the receiving class correctly receives the com.lorenzoff.authenticator.ACTION_UNKNOWN action but how can I establish if was clicked accout_A or account_B?
回答1:
Some experimentation shows that the standard Android Settings app passes the target Account via the key "account"
in the extras Bundle that comes with the Intent that launches the android:accountPreferences
activity.
Unfortunately, I also can't seem see any documentation that guarantees whether this is always true; it'd be great if someone can prove otherwise.
来源:https://stackoverflow.com/questions/18720392/android-account-authenticator-distinguish-between-accounts-in-preference-screen