AbstractAccountAuthenticator简介
来源:互联网 发布:java实现会员注册 编辑:程序博客网 时间:2024/05/08 23:13
Abstract base class for creating AccountAuthenticators. In order to be an authenticator one must extend this class, provider implementations for the abstract methods and write a service that returns the result of getIBinder()
in the service's onBind(android.content.Intent)
when invoked with an intent with actionACTION_AUTHENTICATOR_INTENT
. This service must specify the following intent filter and metadata tags in its AndroidManifest.xml file
android.accounts.AbstractAccountAuthenticator是一个虚类,它定义处理Setting->“Accounts&sync”中Account的添加和验证等功能的基本接口,并实现了一些基本功能。AbstractAccountAuthenticator里面有个继承于IAccountAuthenticator.Stub的内部类,以用来对AbstractAccountAuthenticator的远程接口调用进行包装。我们可以通过AbstractAccountAuthenticator的getIBinder()方法,返回内部类的IBinder形式,以便对AbstractAccountAuthenticator进行远程调用。
为了能让系统找到我们自制的Account的添加和验证等功能的接口函数,我们需要如下定义一个能接受action为ACTION_AUTHENTICATOR_INTENT
的Intent的Service,并在Service的onBind(android.content.Intent)中调AbstractAccountAuthenticator的getIBinder()
返回其用于远程调用的IBinder。
示例1:
<intent-filter> <action android:name="android.accounts.AccountAuthenticator" /> </intent-filter> <meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator" />
示例2(来自SampleSyncAdapter):
<!-- The authenticator service -->
<service android:name=".authenticator.AuthenticationService" android:exported="true"> <intent-filter> <action android:name="android.accounts.AccountAuthenticator" /> </intent-filter> <meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator" /> </service>
android:resource
attribute must point to a resource that looks like:<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android" android:accountType="typeOfAuthenticator" android:icon="@drawable/icon" android:smallIcon="@drawable/miniIcon" android:label="@string/label" android:accountPreferences="@xml/account_preferences" />
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android" android:accountType="com.example.android.samplesync" android:icon="@drawable/icon" android:smallIcon="@drawable/icon" android:label="@string/label"/>
android:accountType
attribute must be a string that uniquely identifies your authenticator and will be the same string that user will use when making calls on the AccountManager
and it also corresponds to type
for your accounts. 使用的android:icon属性的一个地方在 Setting->“Accounts&sync” 设置 ,使用android:smallIcon 属性的一个地方是在Contact Application's tab panels.android:accountPreferences 属性应该指向一个referenceScreen xml hierarchy that contains a list of PreferenceScreens that can be invoked to manage the authenticator. An example is:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="@string/title_fmt" /> <PreferenceScreen android:key="key1" android:title="@string/key1_action" android:summary="@string/key1_summary"> <intent android:action="key1.ACTION" android:targetPackage="key1.package" android:targetClass="key1.class" /> </PreferenceScreen> </PreferenceScreen>
The standard pattern for implementing any of the abstract methods is the following:
- If the supplied arguments are enough for the authenticator to fully satisfy the request then it will do so and return a
Bundle
that contains the results.当提供的参数已经足够的时候,可以直接用Bundler返回结果。 - If the authenticator needs information from the user to satisfy the request then it will create an
Intent
to an activity that will prompt the user for the information and then carry out the request. This intent must be returned in a Bundle as keyKEY_INTENT
.The activity needs to return the final result when it is complete so the Intent should contain the
AccountAuthenticatorResponse
asKEY_ACCOUNT_MANAGER_RESPONSE
. The activity must then callonResult(Bundle)
oronError(int, String)
when it is complete.当提供的参数不充足的时候,可以新建一个指向某个Activity的Intent,并把传进来的 AccountAuthenticatorResponse 参数以KEY_ACCOUNT_MANAGER_RESPONSE 为键放在Intent,然后把启动Activity的相关参数放入其中,最后把Intent以为键放在Bundle的,并返回该Bundle。
这样系统将启动我们所指定的Activity,在Activity中完成工作后通过AccountAuthenticatorResponse的
onResult(Bundle)
oronError(int, String)
返回结果 - If the authenticator cannot synchronously process the request and return a result then it may choose to return null and then use the AccountManagerResponse to send the result when it has completed the request.如果我们想进行的操作是异步操作,而不是同步,可以直接返回null,在操作真正完成后才通过 AccountAuthenticatorResponse 返回操作结果。
The following descriptions of each of the abstract authenticator methods will not describe the possible asynchronous nature of the request handling and will instead just describe the input parameters and the expected result.
When writing an activity to satisfy these requests one must pass in the AccountManagerResponse and return the result via that response when the activity finishes (or whenever else the activity author deems it is the correct time to respond). The AccountAuthenticatorActivity
handles this, so one may wish to extend that when writing activities to handle these requests.
- AbstractAccountAuthenticator简介
- AbstractAccountAuthenticator简介
- 使用AccountManager和AbstractAccountAuthenticator建立账户系统
- 简介
- 简介
- 简介
- 简介
- 简介
- 简介
- 简介
- 简介
- 简介
- 简介
- 简介
- 简介
- 简介
- 简介
- 简介
- hdoj 1983 Kaitou Kid - The Phantom Thief (2) (dfs+bfs)
- Account简介
- 判断浏览器类型
- 迈出从3K到1W的重要一步——掌握设计模式
- 让xcode正确推测静态库依赖关系的两种方法
- AbstractAccountAuthenticator简介
- sql 与 hql 的分页语句
- AccountAuthenticatorActivity简介
- 第四周 任务一
- 程序员真的是吃青春饭的吗?(献给即将进入职场的程序员们)
- ASP去掉字符串中HTML标签的函数
- wlfullclient.jar生成方法
- 强烈推荐:240多个jQuery插件
- AbstractThreadedSyncAdapter简介