Android 账户验证器:区分偏好屏幕中的账户 [英] Android account authenticator: distinguish between accounts in preference screen

查看:29
本文介绍了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 &同步设置并单击其中之一会打开相关的 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 Settings 应用程序通过附带的 extras Bundle 中的键 "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天全站免登陆