AccountManager
open class AccountManager
kotlin.Any | |
↳ | android.accounts.AccountManager |
This class provides access to a centralized registry of the user's online accounts. The user enters credentials (username and password) once per account, granting applications access to online resources with "one-click" approval.
Different online services have different ways of handling accounts and authentication, so the account manager uses pluggable authenticator modules for different account types. Authenticators (which may be written by third parties) handle the actual details of validating account credentials and storing account information. For example, Google, Facebook, and Microsoft Exchange each have their own authenticator.
Many servers support some notion of an authentication token, which can be used to authenticate a request to the server without sending the user's actual password. (Auth tokens are normally created with a separate request which does include the user's credentials.) AccountManager can generate auth tokens for applications, so the application doesn't need to handle passwords directly. Auth tokens are normally reusable and cached by AccountManager, but must be refreshed periodically. It's the responsibility of applications to invalidate auth tokens when they stop working so the AccountManager knows it needs to regenerate them.
Applications accessing a server normally go through these steps:
- Get an instance of AccountManager using
get(android.content.Context)
. - List the available accounts using
getAccountsByType
orgetAccountsByTypeAndFeatures
. Normally applications will only be interested in accounts with one particular type, which identifies the authenticator. Account features are used to identify particular account subtypes and capabilities. Both the account type and features are authenticator-specific strings, and must be known by the application in coordination with its preferred authenticators. - Select one or more of the available accounts, possibly by asking the user for their preference. If no suitable accounts are available,
addAccount
may be called to prompt the user to create an account of the appropriate type. - Important: If the application is using a previously remembered account selection, it must make sure the account is still in the list of accounts returned by
getAccountsByType
. Requesting an auth token for an account no longer on the device results in an undefined failure. - Request an auth token for the selected account(s) using one of the #getAuthToken methods or related helpers. Refer to the description of each method for exact usage and error handling details.
- Make the request using the auth token. The form of the auth token, the format of the request, and the protocol used are all specific to the service you are accessing. The application may use whatever network and protocol libraries are useful.
- Important: If the request fails with an authentication error, it could be that a cached auth token is stale and no longer honored by the server. The application must call
invalidateAuthToken
to remove the token from the cache, otherwise requests will continue failing! After invalidating the auth token, immediately go back to the "Request an auth token" step above. If the process fails the second time, then it can be treated as a "genuine" authentication failure and the user notified or other appropriate actions taken.
Some AccountManager methods may need to interact with the user to prompt for credentials, present options, or ask the user to add an account. The caller may choose whether to allow AccountManager to directly launch the necessary user interface and wait for the user, or to return an Intent which the caller may use to launch the interface, or (in some cases) to install a notification which the user can select at any time to launch the interface. To have AccountManager launch the interface directly, the caller must supply the current foreground Activity
context.
Many AccountManager methods take AccountManagerCallback
and Handler
as parameters. These methods return immediately and run asynchronously. If a callback is provided then AccountManagerCallback.run
will be invoked on the Handler's thread when the request completes, successfully or not. The result is retrieved by calling AccountManagerFuture.getResult()
on the AccountManagerFuture
returned by the method (and also passed to the callback). This method waits for the operation to complete (if necessary) and either returns the result or throws an exception if an error occurred during the operation. To make the request synchronously, call AccountManagerFuture.getResult()
immediately on receiving the future from the method; no callback need be supplied.
Requests which may block, including AccountManagerFuture.getResult()
, must never be called on the application's main event thread. These operations throw IllegalStateException
if they are used on the main thread.
Summary
Constants | |
---|---|
static String |
Action sent as a broadcast Intent by the AccountsService when any account is removed or renamed. |
static String | |
static String | |
static String | |
static Int | |
static Int | |
static Int | |
static Int | |
static Int | |
static Int | |
static Int | |
static Int | |
static String | |
static String | |
static String | |
static String |
Bundle key used for the |
static String |
Bundle key used for a |
static String |
Bundle key used for the |
static String |
Bundle key used for the |
static String |
The Android package of the caller will be set in the options bundle by the |
static String | |
static String |
Bundle key used for the auth token value in results from #getAuthToken and friends. |
static String | |
static String | |
static String | |
static String |
The process id of caller app. |
static String |
The UID of caller app. |
static String | |
static String | |
static String |
Bundle key used for an |
static String |
Bundle key used to supply the last time the credentials of the account were authenticated successfully. |
static String |
Bundle key used to supply the password directly in options to |
static String | |
static String |
Action sent as a broadcast Intent by the AccountsService when accounts are added, accounts are removed, or an account's credentials (saved password, etc) are changed. |
static String |
Key to set default visibility for applications which don't satisfy conditions in |
static String |
Key to set visibility for applications which satisfy one of the following conditions:
getAccountVisibility .
|
static Int |
Account is not visible to given application and only authenticator can grant visibility. |
static Int |
Account visibility was not set. |
static Int |
Account is not visible to given application, but user can reveal it, for example, using |
static Int |
Account is visible to given application, but user can revoke visibility. |
static Int |
Account is always visible to given application and only authenticator can revoke visibility. |
Public methods | |
---|---|
open AccountManagerFuture<Bundle!>! |
addAccount(accountType: String!, authTokenType: String!, requiredFeatures: Array<String!>!, addAccountOptions: Bundle!, activity: Activity!, callback: AccountManagerCallback<Bundle!>!, handler: Handler!) Asks the user to add an account of a specified type. |
open Boolean |
addAccountExplicitly(account: Account!, password: String!, userdata: Bundle!) Adds an account directly to the AccountManager. |
open Boolean |
addAccountExplicitly(account: Account!, password: String!, extras: Bundle!, visibility: MutableMap<String!, Int!>!) Adds an account directly to the AccountManager. |
open Unit |
addOnAccountsUpdatedListener(listener: OnAccountsUpdateListener!, handler: Handler!, updateImmediately: Boolean) Adds an |
open Unit |
addOnAccountsUpdatedListener(listener: OnAccountsUpdateListener!, handler: Handler!, updateImmediately: Boolean, accountTypes: Array<String!>!) Adds an |
open String! |
blockingGetAuthToken(account: Account!, authTokenType: String!, notifyAuthFailure: Boolean) This convenience helper synchronously gets an auth token with |
open Unit |
clearPassword(account: Account!) Forgets a saved password. |
open AccountManagerFuture<Bundle!>! |
confirmCredentials(account: Account!, options: Bundle!, activity: Activity!, callback: AccountManagerCallback<Bundle!>!, handler: Handler!) Confirms that the user knows the password for an account to make extra sure they are the owner of the account. |
open AccountManagerFuture<Bundle!>! |
editProperties(accountType: String!, activity: Activity!, callback: AccountManagerCallback<Bundle!>!, handler: Handler!) Offers the user an opportunity to change an authenticator's settings. |
open AccountManagerFuture<Bundle!>! |
finishSession(sessionBundle: Bundle!, activity: Activity!, callback: AccountManagerCallback<Bundle!>!, handler: Handler!) Finishes the session started by |
open static AccountManager! |
Gets an AccountManager instance associated with a Context. |
open Int |
getAccountVisibility(account: Account!, packageName: String!) Get visibility of certain account for given application. |
open Array<Account!> |
Lists all accounts visible to the caller regardless of type. |
open MutableMap<Account!, Int!>! |
getAccountsAndVisibilityForPackage(packageName: String!, accountType: String!) Gets all accounts of given type and their visibility for specific package. |
open Array<Account!> |
getAccountsByType(type: String!) Lists all accounts of particular type visible to the caller. |
open AccountManagerFuture<Array<Account!>!>! |
getAccountsByTypeAndFeatures(type: String!, features: Array<String!>!, callback: AccountManagerCallback<Array<Account!>!>!, handler: Handler!) Lists all accounts of a type which have certain features. |
open Array<Account!> |
getAccountsByTypeForPackage(type: String!, packageName: String!) Returns the accounts visible to the specified package in an environment where some apps are not authorized to view all accounts. |
open AccountManagerFuture<Bundle!>! |
getAuthToken(account: Account!, authTokenType: String!, options: Bundle!, activity: Activity!, callback: AccountManagerCallback<Bundle!>!, handler: Handler!) Gets an auth token of the specified type for a particular account, prompting the user for credentials if necessary. |
open AccountManagerFuture<Bundle!>! |
getAuthToken(account: Account!, authTokenType: String!, options: Bundle!, notifyAuthFailure: Boolean, callback: AccountManagerCallback<Bundle!>!, handler: Handler!) Gets an auth token of the specified type for a particular account, optionally raising a notification if the user must enter credentials. |
open AccountManagerFuture<Bundle!>! |
getAuthToken(account: Account!, authTokenType: String!, notifyAuthFailure: Boolean, callback: AccountManagerCallback<Bundle!>!, handler: Handler!) Gets an auth token of the specified type for a particular account, optionally raising a notification if the user must enter credentials. |
open AccountManagerFuture<Bundle!>! |
getAuthTokenByFeatures(accountType: String!, authTokenType: String!, features: Array<String!>!, activity: Activity!, addAccountOptions: Bundle!, getAuthTokenOptions: Bundle!, callback: AccountManagerCallback<Bundle!>!, handler: Handler!) This convenience helper combines the functionality of |
open Array<AuthenticatorDescription!>! |
Lists the currently registered authenticators. |
open MutableMap<String!, Int!>! |
getPackagesAndVisibilityForAccount(account: Account!) Returns package names and visibility which were explicitly set for given account. |
open String! |
getPassword(account: Account!) Gets the saved password associated with the account. |
open String! |
getPreviousName(account: Account!) Gets the previous name associated with the account or |
open String! |
getUserData(account: Account!, key: String!) Gets the user data named by "key" associated with the account. |
open AccountManagerFuture<Boolean!>! |
hasFeatures(account: Account!, features: Array<String!>!, callback: AccountManagerCallback<Boolean!>!, handler: Handler!) Finds out whether a particular account has all the specified features. |
open Unit |
invalidateAuthToken(accountType: String!, authToken: String!) Removes an auth token from the AccountManager's cache. |
open AccountManagerFuture<Boolean!>! |
isCredentialsUpdateSuggested(account: Account!, statusToken: String!, callback: AccountManagerCallback<Boolean!>!, handler: Handler!) Checks whether |
open static Intent! |
newChooseAccountIntent(selectedAccount: Account!, allowableAccounts: ArrayList<Account!>!, allowableAccountTypes: Array<String!>!, alwaysPromptForAccount: Boolean, descriptionOverrideText: String!, addAccountAuthTokenType: String!, addAccountRequiredFeatures: Array<String!>!, addAccountOptions: Bundle!) Deprecated in favor of |
open static Intent! |
newChooseAccountIntent(selectedAccount: Account!, allowableAccounts: MutableList<Account!>!, allowableAccountTypes: Array<String!>!, descriptionOverrideText: String!, addAccountAuthTokenType: String!, addAccountRequiredFeatures: Array<String!>!, addAccountOptions: Bundle!) Returns an intent to an |
open Boolean |
notifyAccountAuthenticated(account: Account!) Notifies the system that the account has just been authenticated. |
open String! |
peekAuthToken(account: Account!, authTokenType: String!) Gets an auth token from the AccountManager's cache. |
open AccountManagerFuture<Boolean!>! |
removeAccount(account: Account!, callback: AccountManagerCallback<Boolean!>!, handler: Handler!) Removes an account from the AccountManager. |
open AccountManagerFuture<Bundle!>! |
removeAccount(account: Account!, activity: Activity!, callback: AccountManagerCallback<Bundle!>!, handler: Handler!) Removes an account from the AccountManager. |
open Boolean |
removeAccountExplicitly(account: Account!) Removes an account directly. |
open Unit |
Removes an |
open AccountManagerFuture<Account!>! |
renameAccount(account: Account!, newName: String!, callback: AccountManagerCallback<Account!>!, handler: Handler!) Rename the specified |
open Boolean |
setAccountVisibility(account: Account!, packageName: String!, visibility: Int) Set visibility value of given account to certain package. |
open Unit |
setAuthToken(account: Account!, authTokenType: String!, authToken: String!) Adds an auth token to the AccountManager cache for an account. |
open Unit |
setPassword(account: Account!, password: String!) Sets or forgets a saved password. |
open Unit |
setUserData(account: Account!, key: String!, value: String!) Sets one userdata key for an account. |
open AccountManagerFuture<Bundle!>! |
startAddAccountSession(accountType: String!, authTokenType: String!, requiredFeatures: Array<String!>!, options: Bundle!, activity: Activity!, callback: AccountManagerCallback<Bundle!>!, handler: Handler!) Asks the user to authenticate with an account of a specified type. |
open AccountManagerFuture<Bundle!>! |
startUpdateCredentialsSession(account: Account!, authTokenType: String!, options: Bundle!, activity: Activity!, callback: AccountManagerCallback<Bundle!>!, handler: Handler!) Asks the user to enter a new password for the account but not updating the saved credentials for the account until |
open AccountManagerFuture<Bundle!>! |
updateCredentials(account: Account!, authTokenType: String!, options: Bundle!, activity: Activity!, callback: AccountManagerCallback<Bundle!>!, handler: Handler!) Asks the user to enter a new password for an account, updating the saved credentials for the account. |
Constants
ACTION_ACCOUNT_REMOVED
static val ACTION_ACCOUNT_REMOVED: String
Action sent as a broadcast Intent by the AccountsService when any account is removed or renamed. Only applications which were able to see the account will receive the intent. Intent extra will include the following fields:
-
KEY_ACCOUNT_NAME
- the name of the removed account -
KEY_ACCOUNT_TYPE
- the type of the account
Value: "android.accounts.action.ACCOUNT_REMOVED"
ACTION_AUTHENTICATOR_INTENT
static val ACTION_AUTHENTICATOR_INTENT: String
Value: "android.accounts.AccountAuthenticator"
AUTHENTICATOR_ATTRIBUTES_NAME
static val AUTHENTICATOR_ATTRIBUTES_NAME: String
Value: "account-authenticator"
AUTHENTICATOR_META_DATA_NAME
static val AUTHENTICATOR_META_DATA_NAME: String
Value: "android.accounts.AccountAuthenticator"
ERROR_CODE_BAD_AUTHENTICATION
static val ERROR_CODE_BAD_AUTHENTICATION: Int
Value: 9
ERROR_CODE_INVALID_RESPONSE
static val ERROR_CODE_INVALID_RESPONSE: Int
Value: 5
ERROR_CODE_REMOTE_EXCEPTION
static val ERROR_CODE_REMOTE_EXCEPTION: Int
Value: 1
ERROR_CODE_UNSUPPORTED_OPERATION
static val ERROR_CODE_UNSUPPORTED_OPERATION: Int
Value: 6
KEY_ACCOUNT_AUTHENTICATOR_RESPONSE
static val KEY_ACCOUNT_AUTHENTICATOR_RESPONSE: String
Value: "accountAuthenticatorResponse"
KEY_ACCOUNT_MANAGER_RESPONSE
static val KEY_ACCOUNT_MANAGER_RESPONSE: String
Value: "accountManagerResponse"
KEY_ACCOUNT_NAME
static val KEY_ACCOUNT_NAME: String
Bundle key used for the String
account name in results from methods which return information about a particular account.
Value: "authAccount"
KEY_ACCOUNT_SESSION_BUNDLE
static val KEY_ACCOUNT_SESSION_BUNDLE: String
Bundle key used for a Bundle
in result from startAddAccountSession
and friends which returns session data for installing an account later.
Value: "accountSessionBundle"
KEY_ACCOUNT_STATUS_TOKEN
static val KEY_ACCOUNT_STATUS_TOKEN: String
Bundle key used for the String
account status token in result from startAddAccountSession
and friends which returns information about a particular account.
Value: "accountStatusToken"
KEY_ACCOUNT_TYPE
static val KEY_ACCOUNT_TYPE: String
Bundle key used for the String
account type in results from methods which return information about a particular account.
Value: "accountType"
KEY_ANDROID_PACKAGE_NAME
static val KEY_ANDROID_PACKAGE_NAME: String
The Android package of the caller will be set in the options bundle by the AccountManager
and will be passed to the AccountManagerService and to the AccountAuthenticators. The uid of the caller will be known by the AccountManagerService as well as the AccountAuthenticators so they will be able to verify that the package is consistent with the uid (a uid might be shared by many packages).
Value: "androidPackageName"
KEY_AUTHENTICATOR_TYPES
static val KEY_AUTHENTICATOR_TYPES: String
Value: "authenticator_types"
KEY_AUTHTOKEN
static val KEY_AUTHTOKEN: String
Bundle key used for the auth token value in results from #getAuthToken and friends.
Value: "authtoken"
KEY_AUTH_FAILED_MESSAGE
static val KEY_AUTH_FAILED_MESSAGE: String
Value: "authFailedMessage"
KEY_AUTH_TOKEN_LABEL
static val KEY_AUTH_TOKEN_LABEL: String
Value: "authTokenLabelKey"
KEY_BOOLEAN_RESULT
static val KEY_BOOLEAN_RESULT: String
Value: "booleanResult"
KEY_CALLER_PID
static val KEY_CALLER_PID: String
The process id of caller app.
Value: "callerPid"
KEY_CALLER_UID
static val KEY_CALLER_UID: String
The UID of caller app.
Value: "callerUid"
KEY_INTENT
static val KEY_INTENT: String
Bundle key used for an Intent
in results from methods that may require the caller to interact with the user. The Intent can be used to start the corresponding user interface activity.
Value: "intent"
KEY_LAST_AUTHENTICATED_TIME
static val KEY_LAST_AUTHENTICATED_TIME: String
Bundle key used to supply the last time the credentials of the account were authenticated successfully. Time is specified in milliseconds since epoch. Associated time is updated on successful authentication of account on adding account, confirming credentials, or updating credentials.
Value: "lastAuthenticatedTime"
KEY_PASSWORD
static val KEY_PASSWORD: String
Bundle key used to supply the password directly in options to confirmCredentials
, rather than prompting the user with the standard password prompt.
Value: "password"
LOGIN_ACCOUNTS_CHANGED_ACTION
static valLOGIN_ACCOUNTS_CHANGED_ACTION: String
Deprecated: use #addOnAccountsUpdatedListener to get account updates in runtime.
Action sent as a broadcast Intent by the AccountsService when accounts are added, accounts are removed, or an account's credentials (saved password, etc) are changed.
Value: "android.accounts.LOGIN_ACCOUNTS_CHANGED"
See Also
PACKAGE_NAME_KEY_LEGACY_NOT_VISIBLE
static val PACKAGE_NAME_KEY_LEGACY_NOT_VISIBLE: String
Key to set default visibility for applications which don't satisfy conditions in PACKAGE_NAME_KEY_LEGACY_VISIBLE
. If the value was not set by authenticator VISIBILITY_USER_MANAGED_NOT_VISIBLE
is used.
Value: "android:accounts:key_legacy_not_visible"
PACKAGE_NAME_KEY_LEGACY_VISIBLE
static val PACKAGE_NAME_KEY_LEGACY_VISIBLE: String
Key to set visibility for applications which satisfy one of the following conditions:
- Target API level below
android.os.Build.VERSION_CODES#O
and have deprecatedandroid.Manifest.permission#GET_ACCOUNTS
permission. - Have
android.Manifest.permission#GET_ACCOUNTS_PRIVILEGED
permission. - Have the same signature as authenticator.
- Have
android.Manifest.permission#READ_CONTACTS
permission and account type may be associated with contacts data - (verified byandroid.Manifest.permission#WRITE_CONTACTS
permission check for the authenticator).
getAccountVisibility
. If the value was not set by authenticator VISIBILITY_USER_MANAGED_VISIBLE
is used.
Value: "android:accounts:key_legacy_visible"
VISIBILITY_NOT_VISIBLE
static val VISIBILITY_NOT_VISIBLE: Int
Account is not visible to given application and only authenticator can grant visibility.
Value: 3
VISIBILITY_UNDEFINED
static val VISIBILITY_UNDEFINED: Int
Account visibility was not set. Default visibility value will be used. See PACKAGE_NAME_KEY_LEGACY_VISIBLE
, PACKAGE_NAME_KEY_LEGACY_NOT_VISIBLE
Value: 0
VISIBILITY_USER_MANAGED_NOT_VISIBLE
static val VISIBILITY_USER_MANAGED_NOT_VISIBLE: Int
Account is not visible to given application, but user can reveal it, for example, using newChooseAccountIntent(android.accounts.Account,java.util.List,java.lang.String[],java.lang.String,java.lang.String,java.lang.String[],android.os.Bundle)
Value: 4
VISIBILITY_USER_MANAGED_VISIBLE
static val VISIBILITY_USER_MANAGED_VISIBLE: Int
Account is visible to given application, but user can revoke visibility.
Value: 2
VISIBILITY_VISIBLE
static val VISIBILITY_VISIBLE: Int
Account is always visible to given application and only authenticator can revoke visibility.
Value: 1
Public methods
addAccount
open fun addAccount(
accountType: String!,
authTokenType: String!,
requiredFeatures: Array<String!>!,
addAccountOptions: Bundle!,
activity: Activity!,
callback: AccountManagerCallback<Bundle!>!,
handler: Handler!
): AccountManagerFuture<Bundle!>!
Asks the user to add an account of a specified type. The authenticator for this account type processes this request with the appropriate user interface. If the user does elect to create a new account, the account name is returned.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
NOTE: If targeting your app to work on API level 22 and before, MANAGE_ACCOUNTS permission is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.MANAGE_ACCOUNTS
Parameters | |
---|---|
accountType |
String!: The type of account to add; must not be null |
authTokenType |
String!: The type of auth token (see #getAuthToken) this account will need to be able to generate, null for none |
requiredFeatures |
Array<String!>!: The features (see hasFeatures ) this account must have, null for none |
addAccountOptions |
Bundle!: Authenticator-specific options for the request, may be null or empty |
activity |
Activity!: The Activity context to use for launching a new authenticator-defined sub-Activity to prompt the user to create an account; used only to call startActivity(); if null, the prompt will not be launched directly, but the necessary Intent will be returned to the caller instead |
callback |
AccountManagerCallback<Bundle!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Bundle!>! |
An AccountManagerFuture which resolves to a Bundle with these fields if activity was specified and an account was created:
KEY_INTENT with the Intent needed to launch the actual account creation process. If an error occurred, AccountManagerFuture.getResult() throws:
|
addAccountExplicitly
open fun addAccountExplicitly(
account: Account!,
password: String!,
userdata: Bundle!
): Boolean
Adds an account directly to the AccountManager. Normally used by sign-up wizards associated with authenticators, not directly by applications.
Calling this method does not update the last authenticated timestamp, referred by KEY_LAST_AUTHENTICATED_TIME
. To update it, call notifyAccountAuthenticated(android.accounts.Account)
after getting success. However, if this method is called when it is triggered by addAccount() or addAccountAsUser() or similar functions, then there is no need to update timestamp manually as it is updated automatically by framework on successful completion of the mentioned functions.
It is safe to call this method from the main thread.
This method requires the caller to have a signature match with the authenticator that owns the specified account.
NOTE: If targeting your app to work on API level 22 and before, AUTHENTICATE_ACCOUNTS permission is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.AUTHENTICATE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: The Account to add |
password |
String!: The password to associate with the account, null for none |
userdata |
Bundle!: String values to use for the account's userdata, null for none |
Return | |
---|---|
Boolean |
True if the account was successfully added, false if the account already exists, the account is null, the user is locked, or another error occurs. |
addAccountExplicitly
open fun addAccountExplicitly(
account: Account!,
password: String!,
extras: Bundle!,
visibility: MutableMap<String!, Int!>!
): Boolean
Adds an account directly to the AccountManager. Additionally it specifies Account visibility for given list of packages.
Normally used by sign-up wizards associated with authenticators, not directly by applications.
Calling this method does not update the last authenticated timestamp, referred by KEY_LAST_AUTHENTICATED_TIME
. To update it, call notifyAccountAuthenticated(android.accounts.Account)
after getting success.
It is safe to call this method from the main thread.
This method requires the caller to have a signature match with the authenticator that owns the specified account.
Parameters | |
---|---|
account |
Account!: The Account to add |
password |
String!: The password to associate with the account, null for none |
extras |
Bundle!: String values to use for the account's userdata, null for none |
visibility |
MutableMap<String!, Int!>!: Map from packageName to visibility values which will be set before account is added. See getAccountVisibility for possible values. Declaring package visibility needs for package names in the map is needed, if the caller is targeting API level 34 and above. |
Return | |
---|---|
Boolean |
True if the account was successfully added, false if the account already exists, the account is null, or another error occurs. |
addOnAccountsUpdatedListener
open fun addOnAccountsUpdatedListener(
listener: OnAccountsUpdateListener!,
handler: Handler!,
updateImmediately: Boolean
): Unit
Adds an OnAccountsUpdateListener
to this instance of the AccountManager
. This listener will be notified whenever user or AbstractAccountAuthenticator made changes to accounts of any type related to the caller. This method is equivalent to addOnAccountsUpdatedListener(listener, handler, updateImmediately, null)
Requires android.Manifest.permission#GET_ACCOUNTS
addOnAccountsUpdatedListener
open fun addOnAccountsUpdatedListener(
listener: OnAccountsUpdateListener!,
handler: Handler!,
updateImmediately: Boolean,
accountTypes: Array<String!>!
): Unit
Adds an OnAccountsUpdateListener
to this instance of the AccountManager
. This listener will be notified whenever user or AbstractAccountAuthenticator made changes to accounts of given types related to the caller - either list of accounts returned by getAccounts()
was changed, or new account was added for which user can grant access to the caller.
As long as this listener is present, the AccountManager instance will not be garbage-collected, and neither will the Context
used to retrieve it, which may be a large Activity instance. To avoid memory leaks, you must remove this listener before then. Normally listeners are added in an Activity or Service's android.app.Activity#onCreate and removed in Activity.onDestroy
.
It is safe to call this method from the main thread.
Parameters | |
---|---|
listener |
OnAccountsUpdateListener!: The listener to send notifications to |
handler |
Handler!: Handler identifying the thread to use for notifications, null for the main thread |
updateImmediately |
Boolean: If true, the listener will be invoked (on the handler thread) right away with the current account list |
accountTypes |
Array<String!>!: If set, only changes to accounts of given types will be reported. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if listener is null |
java.lang.IllegalStateException |
if listener was already added |
blockingGetAuthToken
open fun blockingGetAuthToken(
account: Account!,
authTokenType: String!,
notifyAuthFailure: Boolean
): String!
This convenience helper synchronously gets an auth token with getAuthToken(android.accounts.Account,java.lang.String,boolean,android.accounts.AccountManagerCallback,android.os.Handler)
.
This method may block while a network request completes, and must never be made from the main thread.
NOTE: If targeting your app to work on API level 22 and before, USE_CREDENTIALS permission is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.USE_CREDENTIALS
Parameters | |
---|---|
account |
Account!: The account to fetch an auth token for |
authTokenType |
String!: The auth token type, see #getAuthToken |
notifyAuthFailure |
Boolean: If true, display a notification and return null if authentication fails; if false, prompt and wait for the user to re-enter correct credentials before returning |
Return | |
---|---|
String! |
An auth token of the specified type for this account, or null if authentication fails or none can be fetched. |
Exceptions | |
---|---|
android.accounts.AuthenticatorException |
if the authenticator failed to respond |
android.accounts.OperationCanceledException |
if the request was canceled for any reason, including the user canceling a credential request |
java.io.IOException |
if the authenticator experienced an I/O problem creating a new auth token, usually because of network trouble |
clearPassword
open fun clearPassword(account: Account!): Unit
Forgets a saved password. This erases the local copy of the password; it does not change the user's account password on the server. Has the same effect as setPassword(account, null) but requires fewer permissions, and may be used by applications or management interfaces to "sign out" from an account.
This method only successfully clear the account's password when the caller has the same signature as the authenticator that owns the specified account. Otherwise, this method will silently fail.
It is safe to call this method from the main thread.
NOTE: If targeting your app to work on API level 22 and before, MANAGE_ACCOUNTS permission is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.MANAGE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: The account whose password to clear |
confirmCredentials
open fun confirmCredentials(
account: Account!,
options: Bundle!,
activity: Activity!,
callback: AccountManagerCallback<Bundle!>!,
handler: Handler!
): AccountManagerFuture<Bundle!>!
Confirms that the user knows the password for an account to make extra sure they are the owner of the account. The user-entered password can be supplied directly, otherwise the authenticator for this account type prompts the user with the appropriate interface. This method is intended for applications which want extra assurance; for example, the phone lock screen uses this to let the user unlock the phone with an account password if they forget the lock pattern.
If the user-entered password matches a saved password for this account, the request is considered valid; otherwise the authenticator verifies the password (usually by contacting the server).
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
NOTE: If targeting your app to work on API level 22 and before, MANAGE_ACCOUNTS permission is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.MANAGE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: The account to confirm password knowledge for |
options |
Bundle!: Authenticator-specific options for the request; if the KEY_PASSWORD string field is present, the authenticator may use it directly rather than prompting the user; may be null or empty |
activity |
Activity!: The Activity context to use for launching a new authenticator-defined sub-Activity to prompt the user to enter a password; used only to call startActivity(); if null, the prompt will not be launched directly, but the necessary Intent will be returned to the caller instead |
callback |
AccountManagerCallback<Bundle!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Bundle!>! |
An AccountManagerFuture which resolves to a Bundle with these fields if activity or password was supplied and the account was successfully verified:
KEY_INTENT with the Intent needed to launch the password prompt.
Also the returning Bundle may contain
|
editProperties
open fun editProperties(
accountType: String!,
activity: Activity!,
callback: AccountManagerCallback<Bundle!>!,
handler: Handler!
): AccountManagerFuture<Bundle!>!
Offers the user an opportunity to change an authenticator's settings. These properties are for the authenticator in general, not a particular account. Not all authenticators support this method.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
This method requires the caller to have the same signature as the authenticator associated with the specified account type.
NOTE: If targeting your app to work on API level 22 and before, MANAGE_ACCOUNTS permission is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.MANAGE_ACCOUNTS
Parameters | |
---|---|
accountType |
String!: The account type associated with the authenticator to adjust |
activity |
Activity!: The Activity context to use for launching a new authenticator-defined sub-Activity to adjust authenticator settings; used only to call startActivity(); if null, the settings dialog will not be launched directly, but the necessary Intent will be returned to the caller instead |
callback |
AccountManagerCallback<Bundle!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Bundle!>! |
An AccountManagerFuture which resolves to a Bundle which is empty if properties were edited successfully, or if no activity was specified, contains only KEY_INTENT needed to launch the authenticator's settings dialog. If an error occurred, AccountManagerFuture.getResult() throws:
|
finishSession
open fun finishSession(
sessionBundle: Bundle!,
activity: Activity!,
callback: AccountManagerCallback<Bundle!>!,
handler: Handler!
): AccountManagerFuture<Bundle!>!
Finishes the session started by startAddAccountSession
or startUpdateCredentialsSession
. This will either add the account to AccountManager or update the local credentials stored.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
Parameters | |
---|---|
sessionBundle |
Bundle!: a Bundle created by startAddAccountSession or startUpdateCredentialsSession |
activity |
Activity!: The Activity context to use for launching a new authenticator-defined sub-Activity to prompt the user to create an account or reauthenticate existing account; used only to call startActivity(); if null, the prompt will not be launched directly, but the necessary Intent will be returned to the caller instead |
callback |
AccountManagerCallback<Bundle!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Bundle!>! |
An AccountManagerFuture which resolves to a Bundle with these fields if an activity was supplied and an account was added to device or local credentials were updated::
KEY_INTENT with the Intent needed to launch the actual account creation process. If an error occurred, AccountManagerFuture.getResult() throws:
|
See Also
get
open static fun get(context: Context!): AccountManager!
Gets an AccountManager instance associated with a Context. The Context
will be used as long as the AccountManager is active, so make sure to use a Context
whose lifetime is commensurate with any listeners registered to #addOnAccountsUpdatedListener or similar methods.
It is safe to call this method from the main thread.
No permission is required to call this method.
Parameters | |
---|---|
context |
Context!: The Context to use when necessary |
Return | |
---|---|
AccountManager! |
An AccountManager instance |
getAccountVisibility
open fun getAccountVisibility(
account: Account!,
packageName: String!
): Int
Get visibility of certain account for given application. Possible returned values are:
VISIBILITY_VISIBLE
VISIBILITY_USER_MANAGED_VISIBLE
VISIBILITY_NOT_VISIBLE
VISIBILITY_USER_MANAGED_NOT_VISIBLE
This method requires the caller to have a signature match with the authenticator that owns the specified account.
Parameters | |
---|---|
account |
Account!: Account to get visibility |
packageName |
String!: Package name of the application to get account visibility |
Return | |
---|---|
Int |
int Visibility of given account. For the caller targeting API level 34 and above, VISIBILITY_NOT_VISIBLE is returned if the given package is filtered by the rules of package visibility. Value is android.accounts.AccountManager#VISIBILITY_UNDEFINED , android.accounts.AccountManager#VISIBILITY_VISIBLE , android.accounts.AccountManager#VISIBILITY_USER_MANAGED_VISIBLE , android.accounts.AccountManager#VISIBILITY_NOT_VISIBLE , or android.accounts.AccountManager#VISIBILITY_USER_MANAGED_NOT_VISIBLE |
getAccounts
open fun getAccounts(): Array<Account!>
Lists all accounts visible to the caller regardless of type. Equivalent to getAccountsByType(null). These accounts may be visible because the user granted access to the account, or the AbstractAccountAuthenticator managing the account did so or because the client shares a signature with the managing AbstractAccountAuthenticator.
Caution: This method returns personal and sensitive user data. If your app accesses, collects, uses, or shares personal and sensitive data, you must clearly disclose that fact to users. For apps published on Google Play, policies protecting user data require that you do the following:
- Disclose to the user how your app accesses, collects, uses, or shares personal and sensitive data. Learn more about acceptable disclosure and consent.
- Provide a privacy policy that describes your use of this data on- and off-device.
To learn more, visit the Google Play Policy regarding user data.
It is safe to call this method from the main thread.
Requires android.Manifest.permission#GET_ACCOUNTS
Return | |
---|---|
Array<Account!> |
An array of Account , one for each account. Empty (never null) if no accounts have been added. |
getAccountsAndVisibilityForPackage
open fun getAccountsAndVisibilityForPackage(
packageName: String!,
accountType: String!
): MutableMap<Account!, Int!>!
Gets all accounts of given type and their visibility for specific package. This method requires the caller to have a signature match with the authenticator that manages accountType. It is a helper method which combines calls to getAccountsByType
by authenticator and getAccountVisibility
for every returned account.
Parameters | |
---|---|
packageName |
String!: Package name |
accountType |
String!: Account type |
Return | |
---|---|
MutableMap<Account!, Int!>! |
Map with visibility for all accounts of given type See getAccountVisibility for possible values |
getAccountsByType
open fun getAccountsByType(type: String!): Array<Account!>
Lists all accounts of particular type visible to the caller. These accounts may be visible because the user granted access to the account, or the AbstractAccountAuthenticator managing the account did so or because the client shares a signature with the managing AbstractAccountAuthenticator.
The account type is a string token corresponding to the authenticator and useful domain of the account. For example, there are types corresponding to Google and Facebook. The exact string token to use will be published somewhere associated with the authenticator in question.
Caution: This method returns personal and sensitive user data. If your app accesses, collects, uses, or shares personal and sensitive data, you must clearly disclose that fact to users. For apps published on Google Play, policies protecting user data require that you do the following:
- Disclose to the user how your app accesses, collects, uses, or shares personal and sensitive data. Learn more about acceptable disclosure and consent.
- Provide a privacy policy that describes your use of this data on- and off-device.
To learn more, visit the Google Play Policy regarding user data.
It is safe to call this method from the main thread.
Caller targeting API level android.os.Build.VERSION_CODES#O
and above, will get list of accounts made visible to it by user (see newChooseAccountIntent(android.accounts.Account,java.util.List,java.lang.String[],java.lang.String,java.lang.String,java.lang.String[],android.os.Bundle)
) or AbstractAccountAuthenticator using setAccountVisibility
. android.Manifest.permission#GET_ACCOUNTS
permission is not used.
Caller targeting API level below android.os.Build.VERSION_CODES#O
that have not been granted the android.Manifest.permission#GET_ACCOUNTS
permission, will only see those accounts managed by AbstractAccountAuthenticators whose signature matches the client.
NOTE: If targeting your app to work on API level android.os.Build.VERSION_CODES#LOLLIPOP_MR1
and before, android.Manifest.permission#GET_ACCOUNTS
permission is needed for those platforms, irrespective of uid or signature match. See docs for this function in API level android.os.Build.VERSION_CODES#LOLLIPOP_MR1
.
Requires android.Manifest.permission#GET_ACCOUNTS
Parameters | |
---|---|
type |
String!: The type of accounts to return, null to retrieve all accounts |
Return | |
---|---|
Array<Account!> |
An array of Account , one per matching account. Empty (never null) if no accounts of the specified type have been added. |
getAccountsByTypeAndFeatures
open fun getAccountsByTypeAndFeatures(
type: String!,
features: Array<String!>!,
callback: AccountManagerCallback<Array<Account!>!>!,
handler: Handler!
): AccountManagerFuture<Array<Account!>!>!
Lists all accounts of a type which have certain features. The account type identifies the authenticator (see getAccountsByType
). Account features are authenticator-specific string tokens identifying boolean account properties (see hasFeatures
).
Unlike getAccountsByType
, this method calls the authenticator, which may contact the server or do other work to check account features, so the method returns an AccountManagerFuture
.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
Caller targeting API level android.os.Build.VERSION_CODES#O
and above, will get list of accounts made visible to it by user (see newChooseAccountIntent(android.accounts.Account,java.util.List,java.lang.String[],java.lang.String,java.lang.String,java.lang.String[],android.os.Bundle)
) or AbstractAccountAuthenticator using setAccountVisibility
. android.Manifest.permission#GET_ACCOUNTS
permission is not used.
Caller targeting API level below android.os.Build.VERSION_CODES#O
that have not been granted the android.Manifest.permission#GET_ACCOUNTS
permission, will only see those accounts managed by AbstractAccountAuthenticators whose signature matches the client.
NOTE: If targeting your app to work on API level android.os.Build.VERSION_CODES#LOLLIPOP_MR1
and before, android.Manifest.permission#GET_ACCOUNTS
permission is needed for those platforms, irrespective of uid or signature match. See docs for this function in API level android.os.Build.VERSION_CODES#LOLLIPOP_MR1
.
Parameters | |
---|---|
type |
String!: The type of accounts to return, must not be null |
features |
Array<String!>!: An array of the account features to require, may be null or empty * |
callback |
AccountManagerCallback<Array<Account!>!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Array<Account!>!>! |
An AccountManagerFuture which resolves to an array of Account , one per account of the specified type which matches the requested features. |
getAccountsByTypeForPackage
open fun getAccountsByTypeForPackage(
type: String!,
packageName: String!
): Array<Account!>
Returns the accounts visible to the specified package in an environment where some apps are not authorized to view all accounts. This method can only be called by system apps and authenticators managing the type. Beginning API level android.os.Build.VERSION_CODES#O
it also return accounts which user can make visible to the application (see VISIBILITY_USER_MANAGED_VISIBLE
).
Parameters | |
---|---|
type |
String!: The type of accounts to return, null to retrieve all accounts |
packageName |
String!: The package name of the app for which the accounts are to be returned |
Return | |
---|---|
Array<Account!> |
An array of Account , one per matching account. Empty (never null) if no accounts of the specified type can be accessed by the package. |
getAuthToken
open fun getAuthToken(
account: Account!,
authTokenType: String!,
options: Bundle!,
activity: Activity!,
callback: AccountManagerCallback<Bundle!>!,
handler: Handler!
): AccountManagerFuture<Bundle!>!
Gets an auth token of the specified type for a particular account, prompting the user for credentials if necessary. This method is intended for applications running in the foreground where it makes sense to ask the user directly for a password.
If a previously generated auth token is cached for this account and type, then it is returned. Otherwise, if a saved password is available, it is sent to the server to generate a new auth token. Otherwise, the user is prompted to enter a password.
Some authenticators have auth token types, whose value is authenticator-dependent. Some services use different token types to access different functionality -- for example, Google uses different auth tokens to access Gmail and Google Calendar for the same account.
NOTE: If targeting your app to work on API level 22 and before, USE_CREDENTIALS permission is needed for those platforms. See docs for this function in API level 22.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
Requires android.Manifest.permission.USE_CREDENTIALS
Parameters | |
---|---|
account |
Account!: The account to fetch an auth token for |
authTokenType |
String!: The auth token type, an authenticator-dependent string token, must not be null |
options |
Bundle!: Authenticator-specific options for the request, may be null or empty |
activity |
Activity!: The Activity context to use for launching a new authenticator-defined sub-Activity to prompt the user for a password if necessary; used only to call startActivity(); must not be null. |
callback |
AccountManagerCallback<Bundle!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Bundle!>! |
An AccountManagerFuture which resolves to a Bundle with at least the following fields:
AccountManagerFuture.getResult() throws:
|
getAuthToken
open fun getAuthToken(
account: Account!,
authTokenType: String!,
options: Bundle!,
notifyAuthFailure: Boolean,
callback: AccountManagerCallback<Bundle!>!,
handler: Handler!
): AccountManagerFuture<Bundle!>!
Gets an auth token of the specified type for a particular account, optionally raising a notification if the user must enter credentials. This method is intended for background tasks and services where the user should not be immediately interrupted with a password prompt.
If a previously generated auth token is cached for this account and type, then it is returned. Otherwise, if a saved password is available, it is sent to the server to generate a new auth token. Otherwise, an Intent
is returned which, when started, will prompt the user for a password. If the notifyAuthFailure parameter is set, a status bar notification is also created with the same Intent, alerting the user that they need to enter a password at some point.
In that case, you may need to wait until the user responds, which could take hours or days or forever. When the user does respond and supply a new password, the account manager will broadcast the LOGIN_ACCOUNTS_CHANGED_ACTION
Intent and notify OnAccountsUpdateListener
which applications can use to try again.
If notifyAuthFailure is not set, it is the application's responsibility to launch the returned Intent at some point. Either way, the result from this call will not wait for user action.
Some authenticators have auth token types, whose value is authenticator-dependent. Some services use different token types to access different functionality -- for example, Google uses different auth tokens to access Gmail and Google Calendar for the same account.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
NOTE: If targeting your app to work on API level 22 and before, USE_CREDENTIALS permission is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.USE_CREDENTIALS
Parameters | |
---|---|
account |
Account!: The account to fetch an auth token for |
authTokenType |
String!: The auth token type, an authenticator-dependent string token, must not be null |
options |
Bundle!: Authenticator-specific options for the request, may be null or empty |
notifyAuthFailure |
Boolean: True to add a notification to prompt the user for a password if necessary, false to leave that to the caller |
callback |
AccountManagerCallback<Bundle!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Bundle!>! |
An AccountManagerFuture which resolves to a Bundle with at least the following fields on success:
KEY_INTENT with the Intent needed to launch a prompt. If an error occurred, AccountManagerFuture.getResult() throws:
|
getAuthToken
open fungetAuthToken(
account: Account!,
authTokenType: String!,
notifyAuthFailure: Boolean,
callback: AccountManagerCallback<Bundle!>!,
handler: Handler!
): AccountManagerFuture<Bundle!>!
Deprecated: use getAuthToken(android.accounts.Account,java.lang.String,android.os.Bundle,boolean,android.accounts.AccountManagerCallback,android.os.Handler)
instead
Gets an auth token of the specified type for a particular account, optionally raising a notification if the user must enter credentials. This method is intended for background tasks and services where the user should not be immediately interrupted with a password prompt.
If a previously generated auth token is cached for this account and type, then it is returned. Otherwise, if a saved password is available, it is sent to the server to generate a new auth token. Otherwise, an Intent
is returned which, when started, will prompt the user for a password. If the notifyAuthFailure parameter is set, a status bar notification is also created with the same Intent, alerting the user that they need to enter a password at some point.
In that case, you may need to wait until the user responds, which could take hours or days or forever. When the user does respond and supply a new password, the account manager will broadcast the LOGIN_ACCOUNTS_CHANGED_ACTION
Intent and notify OnAccountsUpdateListener
which applications can use to try again.
If notifyAuthFailure is not set, it is the application's responsibility to launch the returned Intent at some point. Either way, the result from this call will not wait for user action.
Some authenticators have auth token types, whose value is authenticator-dependent. Some services use different token types to access different functionality -- for example, Google uses different auth tokens to access Gmail and Google Calendar for the same account.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
Requires android.Manifest.permission.USE_CREDENTIALS
Parameters | |
---|---|
account |
Account!: The account to fetch an auth token for |
authTokenType |
String!: The auth token type, an authenticator-dependent string token, must not be null |
notifyAuthFailure |
Boolean: True to add a notification to prompt the user for a password if necessary, false to leave that to the caller |
callback |
AccountManagerCallback<Bundle!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Bundle!>! |
An AccountManagerFuture which resolves to a Bundle with at least the following fields on success:
KEY_INTENT with the Intent needed to launch a prompt. If an error occurred, AccountManagerFuture.getResult() throws:
|
getAuthTokenByFeatures
open fun getAuthTokenByFeatures(
accountType: String!,
authTokenType: String!,
features: Array<String!>!,
activity: Activity!,
addAccountOptions: Bundle!,
getAuthTokenOptions: Bundle!,
callback: AccountManagerCallback<Bundle!>!,
handler: Handler!
): AccountManagerFuture<Bundle!>!
This convenience helper combines the functionality of getAccountsByTypeAndFeatures
, #getAuthToken, and addAccount
.
This method gets a list of the accounts matching specific type and feature set which are visible to the caller (see getAccountsByType
for details); if there is exactly one already visible account, it is used; if there are some accounts for which user grant visibility, the user is prompted to pick one; if there are none, the user is prompted to add one. Finally, an auth token is acquired for the chosen account.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
NOTE: If targeting your app to work on API level 22 and before, MANAGE_ACCOUNTS permission is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.MANAGE_ACCOUNTS
Parameters | |
---|---|
accountType |
String!: The account type required (see getAccountsByType ), must not be null |
authTokenType |
String!: The desired auth token type (see #getAuthToken), must not be null |
features |
Array<String!>!: Required features for the account (see getAccountsByTypeAndFeatures ), may be null or empty |
activity |
Activity!: The Activity context to use for launching new sub-Activities to prompt to add an account, select an account, and/or enter a password, as necessary; used only to call startActivity(); should not be null |
addAccountOptions |
Bundle!: Authenticator-specific options to use for adding new accounts; may be null or empty |
getAuthTokenOptions |
Bundle!: Authenticator-specific options to use for getting auth tokens; may be null or empty |
callback |
AccountManagerCallback<Bundle!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Bundle!>! |
An AccountManagerFuture which resolves to a Bundle with at least the following fields:
AccountManagerFuture.getResult() throws:
|
getAuthenticatorTypes
open fun getAuthenticatorTypes(): Array<AuthenticatorDescription!>!
Lists the currently registered authenticators.
It is safe to call this method from the main thread.
No permission is required to call this method.
Caller targeting API level 34 and above, the results are filtered by the rules of package visibility.
Return | |
---|---|
Array<AuthenticatorDescription!>! |
An array of AuthenticatorDescription for every authenticator known to the AccountManager service. Empty (never null) if no authenticators are known. |
getPackagesAndVisibilityForAccount
open fun getPackagesAndVisibilityForAccount(account: Account!): MutableMap<String!, Int!>!
Returns package names and visibility which were explicitly set for given account.
This method requires the caller to have a signature match with the authenticator that owns the specified account.
Parameters | |
---|---|
account |
Account!: The account for which visibility data should be returned |
Return | |
---|---|
MutableMap<String!, Int!>! |
Map from package names to visibility for given account |
getPassword
open fun getPassword(account: Account!): String!
Gets the saved password associated with the account. This is intended for authenticators and related code; applications should get an auth token instead.
It is safe to call this method from the main thread.
This method requires the caller to have a signature match with the authenticator that owns the specified account.
NOTE: If targeting your app to work on API level android.os.Build.VERSION_CODES#LOLLIPOP_MR1
and before, AUTHENTICATE_ACCOUNTS permission is needed for those platforms. See docs for this function in API level android.os.Build.VERSION_CODES#LOLLIPOP_MR1
.
Requires android.Manifest.permission.AUTHENTICATE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: The account to query for a password. Must not be null . |
Return | |
---|---|
String! |
The account's password, null if none or if the account doesn't exist |
getPreviousName
open fun getPreviousName(account: Account!): String!
Gets the previous name associated with the account or null
, if none. This is intended so that clients of OnAccountsUpdateListener
can determine if an authenticator has renamed an account.
It is safe to call this method from the main thread.
Parameters | |
---|---|
account |
Account!: The account to query for a previous name. |
Return | |
---|---|
String! |
The account's previous name, null if the account has never been renamed. |
getUserData
open fun getUserData(
account: Account!,
key: String!
): String!
Gets the user data named by "key" associated with the account. This is intended for authenticators and related code to store arbitrary metadata along with accounts. The meaning of the keys and values is up to the authenticator for the account.
It is safe to call this method from the main thread.
This method requires the caller to have a signature match with the authenticator that owns the specified account.
NOTE: If targeting your app to work on API level android.os.Build.VERSION_CODES#LOLLIPOP_MR1
and before, AUTHENTICATE_ACCOUNTS permission is needed for those platforms. See docs for this function in API level android.os.Build.VERSION_CODES#LOLLIPOP_MR1
.
Requires android.Manifest.permission.AUTHENTICATE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: The account to query for user data |
Return | |
---|---|
String! |
The user data, null if the account, key doesn't exist, or the user is locked |
hasFeatures
open fun hasFeatures(
account: Account!,
features: Array<String!>!,
callback: AccountManagerCallback<Boolean!>!,
handler: Handler!
): AccountManagerFuture<Boolean!>!
Finds out whether a particular account has all the specified features. Account features are authenticator-specific string tokens identifying boolean account properties. For example, features are used to tell whether Google accounts have a particular service (such as Google Calendar or Google Talk) enabled. The feature names and their meanings are published somewhere associated with the authenticator in question.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
If caller target API level is below android.os.Build.VERSION_CODES#O
, it is required to hold the permission android.Manifest.permission#GET_ACCOUNTS
or have a signature match with the AbstractAccountAuthenticator that manages the account.
Parameters | |
---|---|
account |
Account!: The Account to test |
features |
Array<String!>!: An array of the account features to check |
callback |
AccountManagerCallback<Boolean!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Boolean!>! |
An AccountManagerFuture which resolves to a Boolean, true if the account exists and has all of the specified features. |
invalidateAuthToken
open fun invalidateAuthToken(
accountType: String!,
authToken: String!
): Unit
Removes an auth token from the AccountManager's cache. Does nothing if the auth token is not currently in the cache. Applications must call this method when the auth token is found to have expired or otherwise become invalid for authenticating requests. The AccountManager does not validate or expire cached auth tokens otherwise.
It is safe to call this method from the main thread.
NOTE: If targeting your app to work on API level 22 and before, MANAGE_ACCOUNTS or USE_CREDENTIALS permission is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.MANAGE_ACCOUNTS or android.Manifest.permission.USE_CREDENTIALS
Parameters | |
---|---|
accountType |
String!: The account type of the auth token to invalidate, must not be null |
authToken |
String!: The auth token to invalidate, may be null |
isCredentialsUpdateSuggested
open fun isCredentialsUpdateSuggested(
account: Account!,
statusToken: String!,
callback: AccountManagerCallback<Boolean!>!,
handler: Handler!
): AccountManagerFuture<Boolean!>!
Checks whether updateCredentials
or startUpdateCredentialsSession
should be called with respect to the specified account.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
Parameters | |
---|---|
account |
Account!: The Account to be checked whether updateCredentials or startUpdateCredentialsSession should be called |
statusToken |
String!: a String of token to check account staus |
callback |
AccountManagerCallback<Boolean!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Boolean!>! |
An AccountManagerFuture which resolves to a Boolean, true if the credentials of the account should be updated. |
newChooseAccountIntent
open static funnewChooseAccountIntent(
selectedAccount: Account!,
allowableAccounts: ArrayList<Account!>!,
allowableAccountTypes: Array<String!>!,
alwaysPromptForAccount: Boolean,
descriptionOverrideText: String!,
addAccountAuthTokenType: String!,
addAccountRequiredFeatures: Array<String!>!,
addAccountOptions: Bundle!
): Intent!
Deprecated: Deprecated in Java.
Deprecated in favor of newChooseAccountIntent(android.accounts.Account,java.util.List,java.lang.String[],java.lang.String,java.lang.String,java.lang.String[],android.os.Bundle)
. Returns an intent to an Activity
that prompts the user to choose from a list of accounts. The caller will then typically start the activity by calling startActivityForResult(intent, ...);
.
On success the activity returns a Bundle with the account name and type specified using keys KEY_ACCOUNT_NAME
and KEY_ACCOUNT_TYPE
. Chosen account is marked as VISIBILITY_USER_MANAGED_VISIBLE
to the caller (see setAccountVisibility
) and will be returned to it in consequent getAccountsByType
) calls.
The most common case is to call this with one account type, e.g.:
newChooseAccountIntent(null, null, new String[]{"com.google"}, false, null, null, null, null);
Parameters | |
---|---|
selectedAccount |
Account!: if specified, indicates that the Account is the currently selected one, according to the caller's definition of selected. |
allowableAccounts |
ArrayList<Account!>!: an optional List of accounts that are allowed to be shown. If not specified then this field will not limit the displayed accounts. |
allowableAccountTypes |
Array<String!>!: an optional string array of account types. These are used both to filter the shown accounts and to filter the list of account types that are shown when adding an account. If not specified then this field will not limit the displayed account types when adding an account. |
alwaysPromptForAccount |
Boolean: boolean that is ignored. |
descriptionOverrideText |
String!: if non-null this string is used as the description in the accounts chooser screen rather than the default |
addAccountAuthTokenType |
String!: this string is passed as the addAccount authTokenType parameter |
addAccountRequiredFeatures |
Array<String!>!: this string array is passed as the addAccount requiredFeatures parameter |
addAccountOptions |
Bundle!: This Bundle is passed as the addAccount options parameter |
Return | |
---|---|
Intent! |
an Intent that can be used to launch the ChooseAccount activity flow. |
newChooseAccountIntent
open static fun newChooseAccountIntent(
selectedAccount: Account!,
allowableAccounts: MutableList<Account!>!,
allowableAccountTypes: Array<String!>!,
descriptionOverrideText: String!,
addAccountAuthTokenType: String!,
addAccountRequiredFeatures: Array<String!>!,
addAccountOptions: Bundle!
): Intent!
Returns an intent to an Activity
that prompts the user to choose from a list of accounts. The caller will then typically start the activity by calling startActivityForResult(intent, ...);
.
On success the activity returns a Bundle with the account name and type specified using keys KEY_ACCOUNT_NAME
and KEY_ACCOUNT_TYPE
. Chosen account is marked as VISIBILITY_USER_MANAGED_VISIBLE
to the caller (see setAccountVisibility
) and will be returned to it in consequent getAccountsByType
) calls.
The most common case is to call this with one account type, e.g.:
newChooseAccountIntent(null, null, new String[]{"com.google"}, null, null, null, null);
Parameters | |
---|---|
selectedAccount |
Account!: if specified, indicates that the Account is the currently selected one, according to the caller's definition of selected. |
allowableAccounts |
MutableList<Account!>!: an optional List of accounts that are allowed to be shown. If not specified then this field will not limit the displayed accounts. |
allowableAccountTypes |
Array<String!>!: an optional string array of account types. These are used both to filter the shown accounts and to filter the list of account types that are shown when adding an account. If not specified then this field will not limit the displayed account types when adding an account. |
descriptionOverrideText |
String!: if non-null this string is used as the description in the accounts chooser screen rather than the default |
addAccountAuthTokenType |
String!: this string is passed as the addAccount authTokenType parameter |
addAccountRequiredFeatures |
Array<String!>!: this string array is passed as the addAccount requiredFeatures parameter |
addAccountOptions |
Bundle!: This Bundle is passed as the addAccount options parameter |
Return | |
---|---|
Intent! |
an Intent that can be used to launch the ChooseAccount activity flow. |
notifyAccountAuthenticated
open fun notifyAccountAuthenticated(account: Account!): Boolean
Notifies the system that the account has just been authenticated. This information may be used by other applications to verify the account. This should be called only when the user has entered correct credentials for the account.
It is not safe to call this method from the main thread. As such, call it from another thread.
This method requires the caller to have a signature match with the authenticator that owns the specified account.
Requires android.Manifest.permission.AUTHENTICATE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: The Account to be updated. |
Return | |
---|---|
Boolean |
boolean true if the authentication of the account has been successfully acknowledged. Otherwise false . |
peekAuthToken
open fun peekAuthToken(
account: Account!,
authTokenType: String!
): String!
Gets an auth token from the AccountManager's cache. If no auth token is cached for this account, null will be returned -- a new auth token will not be generated, and the server will not be contacted. Intended for use by the authenticator, not directly by applications.
It is safe to call this method from the main thread.
This method requires the caller to have a signature match with the authenticator that manages the specified account.
NOTE: If targeting your app to work on API level 22 and before, AUTHENTICATE_ACCOUNTS permission and same UID as account's authenticator is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.AUTHENTICATE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: The account for which an auth token is to be fetched. Cannot be null . |
authTokenType |
String!: The type of auth token to fetch. Cannot be null . |
Return | |
---|---|
String! |
The cached auth token for this account and type, or null if no auth token is cached, the account does not exist, or the user is locked |
See Also
removeAccount
open funremoveAccount(
account: Account!,
callback: AccountManagerCallback<Boolean!>!,
handler: Handler!
): AccountManagerFuture<Boolean!>!
Deprecated: use removeAccount(android.accounts.Account,android.app.Activity,android.accounts.AccountManagerCallback,android.os.Handler)
instead
Removes an account from the AccountManager. Does nothing if the account does not exist. Does not delete the account from the server. The authenticator may have its own policies preventing account deletion, in which case the account will not be deleted.
This method requires the caller to have a signature match with the authenticator that manages the specified account.
NOTE: If targeting your app to work on API level 22 and before, MANAGE_ACCOUNTS permission is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.MANAGE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: The Account to remove |
callback |
AccountManagerCallback<Boolean!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Boolean!>! |
An AccountManagerFuture which resolves to a Boolean, true if the account has been successfully removed |
removeAccount
open fun removeAccount(
account: Account!,
activity: Activity!,
callback: AccountManagerCallback<Bundle!>!,
handler: Handler!
): AccountManagerFuture<Bundle!>!
Removes an account from the AccountManager. Does nothing if the account does not exist. Does not delete the account from the server. The authenticator may have its own policies preventing account deletion, in which case the account will not be deleted.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
This method requires the caller to have a signature match with the authenticator that manages the specified account, be a profile owner or have the android.Manifest.permission#REMOVE_ACCOUNTS permission.
NOTE: If targeting your app to work on API level 22 and before, MANAGE_ACCOUNTS permission is needed for those platforms. See docs for this function in API level 22.
Parameters | |
---|---|
account |
Account!: The Account to remove |
activity |
Activity!: The Activity context to use for launching a new authenticator-defined sub-Activity to prompt the user to delete an account; used only to call startActivity(); if null, the prompt will not be launched directly, but the Intent may be returned to the caller instead |
callback |
AccountManagerCallback<Bundle!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Bundle!>! |
An AccountManagerFuture which resolves to a Bundle with KEY_BOOLEAN_RESULT if activity was specified and an account was removed or if active. If no activity was specified, the returned Bundle contains only KEY_INTENT with the Intent needed to launch the actual account removal process, if authenticator needs the activity launch. If an error occurred, AccountManagerFuture.getResult() throws:
|
removeAccountExplicitly
open fun removeAccountExplicitly(account: Account!): Boolean
Removes an account directly. Normally used by authenticators, not directly by applications. Does not delete the account from the server. The authenticator may have its own policies preventing account deletion, in which case the account will not be deleted.
It is safe to call this method from the main thread.
This method requires the caller to have a signature match with the authenticator that manages the specified account.
NOTE: If targeting your app to work on API level 22 and before, AUTHENTICATE_ACCOUNTS permission and same UID as account's authenticator is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.AUTHENTICATE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: The Account to delete. |
Return | |
---|---|
Boolean |
True if the account was successfully deleted, false if the account did not exist, the account is null, or another error occurs. |
removeOnAccountsUpdatedListener
open fun removeOnAccountsUpdatedListener(listener: OnAccountsUpdateListener!): Unit
Removes an OnAccountsUpdateListener
previously registered with #addOnAccountsUpdatedListener. The listener will no longer receive notifications of account changes.
It is safe to call this method from the main thread.
No permission is required to call this method.
Parameters | |
---|---|
listener |
OnAccountsUpdateListener!: The previously added listener to remove |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if listener is null |
java.lang.IllegalStateException |
if listener was not already added |
renameAccount
open fun renameAccount(
account: Account!,
newName: String!,
callback: AccountManagerCallback<Account!>!,
handler: Handler!
): AccountManagerFuture<Account!>!
Rename the specified Account
. This is equivalent to removing the existing account and adding a new renamed account with the old account's user data.
It is safe to call this method from the main thread.
This method requires the caller to have a signature match with the authenticator that manages the specified account.
NOTE: If targeting your app to work on API level 22 and before, AUTHENTICATE_ACCOUNTS permission and same UID as account's authenticator is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.AUTHENTICATE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: The Account to rename |
newName |
String!: String name to be associated with the account. |
callback |
AccountManagerCallback<Account!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Account!>! |
An AccountManagerFuture which resolves to the Account after the name change. If successful the account's name will be the specified new name. |
setAccountVisibility
open fun setAccountVisibility(
account: Account!,
packageName: String!,
visibility: Int
): Boolean
Set visibility value of given account to certain package. Package name must match installed application, or be equal to PACKAGE_NAME_KEY_LEGACY_VISIBLE
or PACKAGE_NAME_KEY_LEGACY_NOT_VISIBLE
.
Possible visibility values:
VISIBILITY_UNDEFINED
VISIBILITY_VISIBLE
VISIBILITY_USER_MANAGED_VISIBLE
VISIBILITY_NOT_VISIBLE
VISIBILITY_USER_MANAGED_NOT_VISIBLE
This method requires the caller to have a signature match with the authenticator that owns the specified account.
Parameters | |
---|---|
account |
Account!: Account to update visibility |
packageName |
String!: Package name of the application to modify account visibility. Declaring package visibility needs for it is needed, if the caller is targeting API level 34 and above. |
visibility |
Int: New visibility value Value is android.accounts.AccountManager#VISIBILITY_UNDEFINED , android.accounts.AccountManager#VISIBILITY_VISIBLE , android.accounts.AccountManager#VISIBILITY_USER_MANAGED_VISIBLE , android.accounts.AccountManager#VISIBILITY_NOT_VISIBLE , or android.accounts.AccountManager#VISIBILITY_USER_MANAGED_NOT_VISIBLE |
Return | |
---|---|
Boolean |
True, if visibility value was successfully updated. |
setAuthToken
open fun setAuthToken(
account: Account!,
authTokenType: String!,
authToken: String!
): Unit
Adds an auth token to the AccountManager cache for an account. If the account does not exist then this call has no effect. Replaces any previous auth token for this account and auth token type. Intended for use by the authenticator, not directly by applications.
It is safe to call this method from the main thread.
This method requires the caller to have a signature match with the authenticator that manages the specified account.
NOTE: If targeting your app to work on API level 22 and before, AUTHENTICATE_ACCOUNTS permission and same UID as account's authenticator is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.AUTHENTICATE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: The account to set an auth token for |
authTokenType |
String!: The type of the auth token, see {#getAuthToken} |
authToken |
String!: The auth token to add to the cache |
setPassword
open fun setPassword(
account: Account!,
password: String!
): Unit
Sets or forgets a saved password. This modifies the local copy of the password used to automatically authenticate the user; it does not change the user's account password on the server. Intended for use by the authenticator, not directly by applications.
Calling this method does not update the last authenticated timestamp, referred by KEY_LAST_AUTHENTICATED_TIME
. To update it, call notifyAccountAuthenticated(android.accounts.Account)
after getting success.
It is safe to call this method from the main thread.
This method requires the caller to have a signature match with the authenticator that manages the specified account.
NOTE: If targeting your app to work on API level 22 and before, AUTHENTICATE_ACCOUNTS permission and same UID as account's authenticator is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.AUTHENTICATE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: The account whose password is to be set. Cannot be null . |
password |
String!: The password to set, null to clear the password |
setUserData
open fun setUserData(
account: Account!,
key: String!,
value: String!
): Unit
Sets one userdata key for an account. Intended by use for the authenticator to stash state for itself, not directly by applications. The meaning of the keys and values is up to the authenticator.
It is safe to call this method from the main thread.
This method requires the caller to have a signature match with the authenticator that manages the specified account.
NOTE: If targeting your app to work on API level 22 and before, AUTHENTICATE_ACCOUNTS permission and same UID as account's authenticator is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.AUTHENTICATE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: Account whose user data is to be set. Must not be null . |
key |
String!: String user data key to set. Must not be null |
value |
String!: String value to set, null to clear this user data key |
startAddAccountSession
open fun startAddAccountSession(
accountType: String!,
authTokenType: String!,
requiredFeatures: Array<String!>!,
options: Bundle!,
activity: Activity!,
callback: AccountManagerCallback<Bundle!>!,
handler: Handler!
): AccountManagerFuture<Bundle!>!
Asks the user to authenticate with an account of a specified type. The authenticator for this account type processes this request with the appropriate user interface. If the user does elect to authenticate with a new account, a bundle of session data for installing the account later is returned with optional account password and account status token.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
NOTE: The account will not be installed to the device by calling this api alone. #finishSession should be called after this to install the account on device.
Parameters | |
---|---|
accountType |
String!: The type of account to add; must not be null |
authTokenType |
String!: The type of auth token (see #getAuthToken) this account will need to be able to generate, null for none |
requiredFeatures |
Array<String!>!: The features (see hasFeatures ) this account must have, null for none |
options |
Bundle!: Authenticator-specific options for the request, may be null or empty |
activity |
Activity!: The Activity context to use for launching a new authenticator-defined sub-Activity to prompt the user to create an account; used only to call startActivity(); if null, the prompt will not be launched directly, but the necessary Intent will be returned to the caller instead |
callback |
AccountManagerCallback<Bundle!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Bundle!>! |
An AccountManagerFuture which resolves to a Bundle with these fields if activity was specified and user was authenticated with an account:
KEY_INTENT with the Intent needed to launch the actual account creation process. If authenticator doesn't support this method, the returned Bundle contains only KEY_ACCOUNT_SESSION_BUNDLE with encrypted options needed to add account later. If an error occurred, AccountManagerFuture.getResult() throws:
|
See Also
startUpdateCredentialsSession
open fun startUpdateCredentialsSession(
account: Account!,
authTokenType: String!,
options: Bundle!,
activity: Activity!,
callback: AccountManagerCallback<Bundle!>!,
handler: Handler!
): AccountManagerFuture<Bundle!>!
Asks the user to enter a new password for the account but not updating the saved credentials for the account until finishSession
is called.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
NOTE: The saved credentials for the account alone will not be updated by calling this API alone. #finishSession should be called after this to update local credentials
Parameters | |
---|---|
account |
Account!: The account to update credentials for |
authTokenType |
String!: The credentials entered must allow an auth token of this type to be created (but no actual auth token is returned); may be null |
options |
Bundle!: Authenticator-specific options for the request; may be null or empty |
activity |
Activity!: The Activity context to use for launching a new authenticator-defined sub-Activity to prompt the user to enter a password; used only to call startActivity(); if null, the prompt will not be launched directly, but the necessary Intent will be returned to the caller instead |
callback |
AccountManagerCallback<Bundle!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Bundle!>! |
An AccountManagerFuture which resolves to a Bundle with these fields if an activity was supplied and user was successfully re-authenticated to the account:
KEY_INTENT with the Intent needed to launch the password prompt. If an error occurred, AccountManagerFuture.getResult() throws:
|
See Also
updateCredentials
open fun updateCredentials(
account: Account!,
authTokenType: String!,
options: Bundle!,
activity: Activity!,
callback: AccountManagerCallback<Bundle!>!,
handler: Handler!
): AccountManagerFuture<Bundle!>!
Asks the user to enter a new password for an account, updating the saved credentials for the account. Normally this happens automatically when the server rejects credentials during an auth token fetch, but this can be invoked directly to ensure we have the correct credentials stored.
This method may be called from any thread, but the returned AccountManagerFuture
must not be used on the main thread.
NOTE: If targeting your app to work on API level 22 and before, MANAGE_ACCOUNTS permission is needed for those platforms. See docs for this function in API level 22.
Requires android.Manifest.permission.MANAGE_ACCOUNTS
Parameters | |
---|---|
account |
Account!: The account to update credentials for |
authTokenType |
String!: The credentials entered must allow an auth token of this type to be created (but no actual auth token is returned); may be null |
options |
Bundle!: Authenticator-specific options for the request; may be null or empty |
activity |
Activity!: The Activity context to use for launching a new authenticator-defined sub-Activity to prompt the user to enter a password; used only to call startActivity(); if null, the prompt will not be launched directly, but the necessary Intent will be returned to the caller instead |
callback |
AccountManagerCallback<Bundle!>!: Callback to invoke when the request completes, null for no callback |
handler |
Handler!: Handler identifying the callback thread, null for the main thread |
Return | |
---|---|
AccountManagerFuture<Bundle!>! |
An AccountManagerFuture which resolves to a Bundle with these fields if an activity was supplied and the account credentials were successfully updated:
KEY_INTENT with the Intent needed to launch the password prompt. If an error occurred, AccountManagerFuture.getResult() throws:
|