AbstractAccountAuthenticator
public abstract class AbstractAccountAuthenticator
extends Object
用于创建AccountAuthenticators的抽象基类。 为了成为认证者,必须扩展这个类,抽象方法的提供者实现,并编写一个服务,该服务返回getIBinder()
服务的onBind(android.content.Intent)
的结果,并以意向为动作ACTION_AUTHENTICATOR_INTENT
调用。 此服务必须在其AndroidManifest.xml文件中指定以下意图过滤器和元数据标记
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
The
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"
/>
Replace the icons and labels with your own resources. The
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. One user of the android:icon is the "Account & Sync" settings page and one user of the android:smallIcon is the Contact Application's tab panels.
preferences属性指向PreferenceScreen xml层次结构,其中包含可以调用以管理认证者的PreferenceScreen列表。 一个例子是:
<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>
实现任何抽象方法的标准模式如下:
以下对每个抽象认证方法的描述将不会描述请求处理的可能异步性质,而只是描述输入参数和预期结果。
在编写活动以满足这些请求时,必须通过AccountManagerResponse并在活动结束时(或活动作者认为它是正确响应的时间)通过该响应返回结果。 AccountAuthenticatorActivity
处理这个问题,所以在编写处理这些请求的活动时可能希望扩展这个。
Summary
Public methods |
abstract Bundle |
addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) 添加指定帐户类型的帐户。 |
Bundle |
addAccountFromCredentials(AccountAuthenticatorResponse response, Account account, Bundle accountCredentials) 根据设备上其他用户的验证器实例提供的凭据创建帐户,该用户已选择与该用户共享该帐户。 |
abstract Bundle |
confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) 检查用户是否知道帐户的凭证。 |
abstract Bundle |
editProperties(AccountAuthenticatorResponse response, String accountType) 返回一个包含可用于编辑属性的活动的Intent的Bundle。 |
Bundle |
getAccountCredentialsForCloning(AccountAuthenticatorResponse response, Account account) 返回一个Bundle,其中包含克隆不同用户帐户所需的任何内容。 |
Bundle |
getAccountRemovalAllowed(AccountAuthenticatorResponse response, Account account) 检查是否允许删除此帐户。 |
abstract Bundle |
getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) 获取帐户的authtoken。 |
abstract String |
getAuthTokenLabel(String authTokenType) 向认证者请求给定authTokenType的本地化标签。 |
final IBinder |
getIBinder() |
abstract Bundle |
hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) 检查帐户是否支持所有指定的验证器特定功能。 |
abstract Bundle |
updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) 更新帐户的本地存储凭据。 |
Constants
KEY_CUSTOM_TOKEN_EXPIRY
String KEY_CUSTOM_TOKEN_EXPIRY
捆绑密钥用于相关身份验证令牌的 long
到期时间(以 long
纪元为单位)。
常量值:“android.accounts.expiry”
Public constructors
AbstractAccountAuthenticator
AbstractAccountAuthenticator (Context context)
Parameters |
context |
Context
|
Public methods
addAccount
Bundle addAccount (AccountAuthenticatorResponse response,
String accountType,
String authTokenType,
String[] requiredFeatures,
Bundle options)
添加指定帐户类型的帐户。
Parameters |
response |
AccountAuthenticatorResponse : to send the result back to the AccountManager, will never be null |
accountType |
String : the type of account to add, will never be null |
authTokenType |
String : the type of auth token to retrieve after adding the account, may be null |
requiredFeatures |
String : a String array of authenticator-specific features that the added account must support, may be null |
options |
Bundle : a Bundle of authenticator-specific options, may be null |
Returns |
Bundle |
a Bundle result or null if the result is to be returned via the response. The result will contain either:
|
addAccountFromCredentials
Bundle addAccountFromCredentials (AccountAuthenticatorResponse response,
Account account,
Bundle accountCredentials)
根据设备上其他用户的验证器实例提供的凭据创建帐户,该用户已选择与该用户共享该帐户。
Parameters |
response |
AccountAuthenticatorResponse : to send the result back to the AccountManager, will never be null |
account |
Account : the account to clone, will never be null |
accountCredentials |
Bundle : the Bundle containing the required credentials to create the account. Contents of the Bundle are only meaningful to the authenticator. This Bundle is provided by getAccountCredentialsForCloning(AccountAuthenticatorResponse, Account) . |
Returns |
Bundle |
a Bundle result or null if the result is to be returned via the response. |
confirmCredentials
Bundle confirmCredentials (AccountAuthenticatorResponse response,
Account account,
Bundle options)
检查用户是否知道帐户的凭证。
Parameters |
response |
AccountAuthenticatorResponse : to send the result back to the AccountManager, will never be null |
account |
Account : the account whose credentials are to be checked, will never be null |
options |
Bundle : a Bundle of authenticator-specific options, may be null |
Returns |
Bundle |
a Bundle result or null if the result is to be returned via the response. The result will contain either:
|
editProperties
Bundle editProperties (AccountAuthenticatorResponse response,
String accountType)
返回一个包含可用于编辑属性的活动的Intent的Bundle。 为了表示成功,活动应该使用非空的Bundle调用response.setResult()。
Parameters |
response |
AccountAuthenticatorResponse : used to set the result for the request. If the Constants.INTENT_KEY is set in the bundle then this response field is to be used for sending future results if and when the Intent is started. |
accountType |
String : the AccountType whose properties are to be edited. |
Returns |
Bundle |
a Bundle containing the result or the Intent to start to continue the request. If this is null then the request is considered to still be active and the result should sent later using response. |
getAccountRemovalAllowed
Bundle getAccountRemovalAllowed (AccountAuthenticatorResponse response,
Account account)
检查是否允许删除此帐户。
Parameters |
response |
AccountAuthenticatorResponse : to send the result back to the AccountManager, will never be null |
account |
Account : the account to check, will never be null |
Returns |
Bundle |
a Bundle result or null if the result is to be returned via the response. The result will contain either:
|
getAuthTokenLabel
String getAuthTokenLabel (String authTokenType)
向认证者请求给定authTokenType的本地化标签。
Parameters |
authTokenType |
String : the authTokenType whose label is to be returned, will never be null |
Returns |
String |
the localized label of the auth token type, may be null if the type isn't known |
getIBinder
IBinder getIBinder ()
Returns |
IBinder |
the IBinder for the AccountAuthenticator |
hasFeatures
Bundle hasFeatures (AccountAuthenticatorResponse response,
Account account,
String[] features)
检查帐户是否支持所有指定的验证器特定功能。
Parameters |
response |
AccountAuthenticatorResponse : to send the result back to the AccountManager, will never be null |
account |
Account : the account to check, will never be null |
features |
String : an array of features to check, will never be null |
Returns |
Bundle |
a Bundle result or null if the result is to be returned via the response. The result will contain either:
|
updateCredentials
Bundle updateCredentials (AccountAuthenticatorResponse response,
Account account,
String authTokenType,
Bundle options)
更新帐户的本地存储凭据。
Parameters |
response |
AccountAuthenticatorResponse : to send the result back to the AccountManager, will never be null |
account |
Account : the account whose credentials are to be updated, will never be null |
authTokenType |
String : the type of auth token to retrieve after updating the credentials, may be null |
options |
Bundle : a Bundle of authenticator-specific options, may be null |
Returns |
Bundle |
a Bundle result or null if the result is to be returned via the response. The result will contain either:
|