java.lang.Object | |
↳ | android.accounts.AbstractAccountAuthenticator |
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 action ACTION_AUTHENTICATOR_INTENT
. This service
must specify the following intent filter and metadata tags in its AndroidManifest.xml file
<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.
The preferences attribute points to a PreferenceScreen 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:
Bundle
that contains the results.
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 key
KEY_INTENT
.
The activity needs to return the final result when it is complete so the Intent should contain
the AccountAuthenticatorResponse
as KEY_ACCOUNT_MANAGER_RESPONSE
.
The activity must then call onResult(Bundle)
or
onError(int, String)
when it is complete.
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.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds an account of the specified accountType.
| |||||||||||
Creates an account based on credentials provided by the authenticator instance of another
user on the device, who has chosen to share the account with this user.
| |||||||||||
Checks that the user knows the credentials of an account.
| |||||||||||
Returns a Bundle that contains the Intent of the activity that can be used to edit the
properties.
| |||||||||||
Returns a Bundle that contains whatever is required to clone the account on a different
user.
| |||||||||||
Checks if the removal of this account is allowed.
| |||||||||||
Gets the authtoken for an account.
| |||||||||||
Ask the authenticator for a localized label for the given authTokenType.
| |||||||||||
Checks if the account supports all the specified authenticator specific features.
| |||||||||||
Update the locally stored credentials for an account.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Adds an account of the specified accountType.
response | to send the result back to the AccountManager, will never be null |
---|---|
accountType | the type of account to add, will never be null |
authTokenType | the type of auth token to retrieve after adding the account, may be null |
requiredFeatures | a String array of authenticator-specific features that the added account must support, may be null |
options | a Bundle of authenticator-specific options, may be null |
KEY_INTENT
, or
KEY_ACCOUNT_NAME
and KEY_ACCOUNT_TYPE
of
the account that was added, or
KEY_ERROR_CODE
and KEY_ERROR_MESSAGE
to
indicate an error
NetworkErrorException | if the authenticator could not honor the request due to a network error |
---|
Creates an account based on credentials provided by the authenticator instance of another user on the device, who has chosen to share the account with this user.
response | to send the result back to the AccountManager, will never be null |
---|---|
account | the account to clone, will never be null |
accountCredentials | 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) . |
NetworkErrorException | |
NetworkErrorException |
Checks that the user knows the credentials of an account.
response | to send the result back to the AccountManager, will never be null |
---|---|
account | the account whose credentials are to be checked, will never be null |
options | a Bundle of authenticator-specific options, may be null |
KEY_INTENT
, or
KEY_BOOLEAN_RESULT
, true if the check succeeded, false otherwise
KEY_ERROR_CODE
and KEY_ERROR_MESSAGE
to
indicate an error
NetworkErrorException | if the authenticator could not honor the request due to a network error |
---|
Returns a Bundle that contains the Intent of the activity that can be used to edit the properties. In order to indicate success the activity should call response.setResult() with a non-null Bundle.
response | 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 | the AccountType whose properties are to be edited. |
Returns a Bundle that contains whatever is required to clone the account on a different
user. The Bundle is passed to the authenticator instance in the target user via
addAccountFromCredentials(AccountAuthenticatorResponse, Account, Bundle)
.
The default implementation returns null, indicating that cloning is not supported.
response | to send the result back to the AccountManager, will never be null |
---|---|
account | the account to clone, will never be null |
NetworkErrorException | |
NetworkErrorException |
Checks if the removal of this account is allowed.
response | to send the result back to the AccountManager, will never be null |
---|---|
account | the account to check, will never be null |
KEY_INTENT
, or
KEY_BOOLEAN_RESULT
, true if the removal of the account is
allowed, false otherwise
KEY_ERROR_CODE
and KEY_ERROR_MESSAGE
to
indicate an error
NetworkErrorException | if the authenticator could not honor the request due to a network error |
---|
Gets the authtoken for an account.
response | to send the result back to the AccountManager, will never be null |
---|---|
account | the account whose credentials are to be retrieved, will never be null |
authTokenType | the type of auth token to retrieve, will never be null |
options | a Bundle of authenticator-specific options, may be null |
KEY_INTENT
, or
KEY_ACCOUNT_NAME
, KEY_ACCOUNT_TYPE
,
and KEY_AUTHTOKEN
, or
KEY_ERROR_CODE
and KEY_ERROR_MESSAGE
to
indicate an error
NetworkErrorException | if the authenticator could not honor the request due to a network error |
---|
Ask the authenticator for a localized label for the given authTokenType.
authTokenType | the authTokenType whose label is to be returned, will never be null |
---|
Checks if the account supports all the specified authenticator specific features.
response | to send the result back to the AccountManager, will never be null |
---|---|
account | the account to check, will never be null |
features | an array of features to check, will never be null |
KEY_INTENT
, or
KEY_BOOLEAN_RESULT
, true if the account has all the features,
false otherwise
KEY_ERROR_CODE
and KEY_ERROR_MESSAGE
to
indicate an error
NetworkErrorException | if the authenticator could not honor the request due to a network error |
---|
Update the locally stored credentials for an account.
response | to send the result back to the AccountManager, will never be null |
---|---|
account | the account whose credentials are to be updated, will never be null |
authTokenType | the type of auth token to retrieve after updating the credentials, may be null |
options | a Bundle of authenticator-specific options, may be null |
KEY_INTENT
, or
KEY_ACCOUNT_NAME
and KEY_ACCOUNT_TYPE
of
the account that was added, or
KEY_ERROR_CODE
and KEY_ERROR_MESSAGE
to
indicate an error
NetworkErrorException | if the authenticator could not honor the request due to a network error |
---|