Android account authenticator: distinguish between accounts in preference screen

匆匆过客 提交于 2019-12-11 19:27:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!