Most visited

Recently visited

Added in API level 5

AbstractAccountAuthenticator

public abstract class AbstractAccountAuthenticator
extends Object

java.lang.Object
   ↳ android.accounts.AbstractAccountAuthenticator


用于创建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

Constants

String KEY_CUSTOM_TOKEN_EXPIRY

捆绑密钥用于相关身份验证令牌的 long到期时间(以 long纪元为单位)。

Public constructors

AbstractAccountAuthenticator(Context context)

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)

更新帐户的本地存储凭据。

Inherited methods

From class java.lang.Object

Constants

KEY_CUSTOM_TOKEN_EXPIRY

Added in API level 23
String KEY_CUSTOM_TOKEN_EXPIRY

捆绑密钥用于相关身份验证令牌的 long到期时间(以 long纪元为单位)。

也可以看看:

常量值:“android.accounts.expiry”

Public constructors

AbstractAccountAuthenticator

Added in API level 5
AbstractAccountAuthenticator (Context context)

Parameters
context Context

Public methods

addAccount

Added in API level 5
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:
Throws
NetworkErrorException if the authenticator could not honor the request due to a network error

addAccountFromCredentials

Added in API level 18
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.
Throws
NetworkErrorException
NetworkErrorException

也可以看看:

confirmCredentials

Added in API level 5
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:
Throws
NetworkErrorException if the authenticator could not honor the request due to a network error

editProperties

Added in API level 5
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.

getAccountCredentialsForCloning

Added in API level 18
Bundle getAccountCredentialsForCloning (AccountAuthenticatorResponse response, 
                Account account)

返回一个Bundle,其中包含克隆不同用户帐户所需的任何内容。 该捆绑包通过addAccountFromCredentials(AccountAuthenticatorResponse, Account, Bundle)传递给目标用户的验证器实例。 默认实现返回null,表示不支持克隆。

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
Returns
Bundle a Bundle result or null if the result is to be returned via the response.
Throws
NetworkErrorException
NetworkErrorException

也可以看看:

getAccountRemovalAllowed

Added in API level 5
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:
Throws
NetworkErrorException if the authenticator could not honor the request due to a network error

getAuthToken

Added in API level 5
Bundle getAuthToken (AccountAuthenticatorResponse response, 
                Account account, 
                String authTokenType, 
                Bundle options)

获取帐户的authtoken。 如果不是null ,则由此产生的Bundle将包含不同组密钥,这取决于令牌是否成功发布,如果不是,则可以通过某些Activity发布Activity

如果没有一些额外的活动就无法提供令牌,那么Bundle应该包含KEY_INTENT和相关的Intent 另一方面,如果没有这样的活动,那么应该返回一个包含KEY_ERROR_CODEKEY_ERROR_MESSAGE的Bundle。

如果令牌可以成功发布,则实现应返回与令牌关联的帐户的KEY_ACCOUNT_NAMEKEY_ACCOUNT_TYPE以及KEY_AUTHTOKEN 另外,声明android:customTokens=true AbstractAccountAuthenticator实现还可以提供包含到期时间的过期时间戳的非负KEY_CUSTOM_TOKEN_EXPIRY长度值(自unix时期以来,以毫秒为单位)。

实施者应该假设令牌将以帐户和authTokenType为基础进行缓存。 当确定重新使用缓存的令牌时,系统可能忽略提供的选项Bundle的内容。 此外,实施者应该假定提供的到期时间将被视为无约束力的建议。

最后,请注意,对于android:customTokens = false验证器,令牌将无限期地缓存,直到某些客户端调用 invalidateAuthToken(String, String)

Parameters
response AccountAuthenticatorResponse: to send the result back to the AccountManager, will never be null
account Account: the account whose credentials are to be retrieved, will never be null
authTokenType String: the type of auth token to retrieve, 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.
Throws
NetworkErrorException if the authenticator could not honor the request due to a network error

getAuthTokenLabel

Added in API level 5
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

Added in API level 5
IBinder getIBinder ()

Returns
IBinder the IBinder for the AccountAuthenticator

hasFeatures

Added in API level 5
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:
Throws
NetworkErrorException if the authenticator could not honor the request due to a network error

updateCredentials

Added in API level 5
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:
Throws
NetworkErrorException if the authenticator could not honor the request due to a network error

Hooray!