Android帐户验证器:区分首选项屏幕中的帐户 [英] Android account authenticator: distinguish between accounts in preference screen

查看:106
本文介绍了Android帐户验证器:区分首选项屏幕中的帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的帐户身份验证器就像一个超级按钮,其xml或多或少是这样的:

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" />

通过此身份验证器,可以管理一个以上的帐户,假设account_A,account_B。
定义两个帐户后,访问帐户&同步设置并单击其中之一将打开相对的account_preferences屏幕。
其xml或多或少是这种方式:

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>

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

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?

推荐答案

一些实验表明,标准的Android设置应用通过附赠的捆绑包中的键 account 传递了目标帐户启动 android:accountPreferences 活动的Intent。

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.

这篇关于Android帐户验证器:区分首选项屏幕中的帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆