AccountManager Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
This class provides access to a centralized registry of the user's online accounts.
[Android.Runtime.Register("android/accounts/AccountManager", DoNotGenerateAcw=true)]
public class AccountManager : Java.Lang.Object
[<Android.Runtime.Register("android/accounts/AccountManager", DoNotGenerateAcw=true)>]
type AccountManager = class
inherit Object
- Inheritance
- Attributes
Remarks
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 <em>authenticator</em> modules for different <em>account types</em>. 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 <em>authentication token</em>, 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 <em>invalidate</em> auth tokens when they stop working so the AccountManager knows it needs to regenerate them.
Applications accessing a server normally go through these steps:
<ul> <li>Get an instance of AccountManager using #get(Context)
.
<li>List the available accounts using #getAccountsByType
or #getAccountsByTypeAndFeatures
. Normally applications will only be interested in accounts with one particular <em>type</em>, which identifies the authenticator. Account <em>features</em> 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.
<li>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.
<li><b>Important:</b> 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.
<li>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.
<li>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.
<li><b>Important:</b> 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. </ul>
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.
Java documentation for android.accounts.AccountManager
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Constructors
AccountManager(IntPtr, JniHandleOwnership) |
A constructor used when creating managed representations of JNI objects; called by the runtime. |
Fields
ActionAccountRemoved |
Action sent as a broadcast Intent by the AccountsService when any account is removed or renamed. |
ActionAuthenticatorIntent | |
AuthenticatorAttributesName | |
AuthenticatorMetaDataName | |
ErrorCodeBadArguments | |
ErrorCodeBadAuthentication | |
ErrorCodeBadRequest | |
ErrorCodeCanceled | |
ErrorCodeInvalidResponse | |
ErrorCodeNetworkError | |
ErrorCodeRemoteException | |
ErrorCodeUnsupportedOperation | |
KeyAccountAuthenticatorResponse | |
KeyAccountManagerResponse | |
KeyAccountName |
Bundle key used for the |
KeyAccounts | |
KeyAccountSessionBundle |
Bundle key used for a |
KeyAccountStatusToken |
Bundle key used for the |
KeyAccountType |
Bundle key used for the |
KeyAndroidPackageName |
The Android package of the caller will be set in the options bundle by the
|
KeyAuthenticatorTypes | |
KeyAuthFailedMessage | |
KeyAuthtoken |
Bundle key used for the auth token value in results
from |
KeyAuthTokenLabel | |
KeyBooleanResult | |
KeyCallerPid |
The process id of caller app. |
KeyCallerUid |
The UID of caller app. |
KeyErrorCode | |
KeyErrorMessage | |
KeyIntent |
Bundle key used for an |
KeyLastAuthenticatedTime |
Bundle key used to supply the last time the credentials of the account were authenticated successfully. |
KeyPassword |
Bundle key used to supply the password directly in options to
|
KeyUserdata | |
LoginAccountsChangedAction |
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. |
PackageNameKeyLegacyNotVisible |
Key to set default visibility for applications which don't satisfy conditions in
|
PackageNameKeyLegacyVisible |
Key to set visibility for applications which satisfy one of the following conditions:
<ul>
<li>Target API level below |
Properties
Class |
Returns the runtime class of this |
Handle |
The handle to the underlying Android instance. (Inherited from Object) |
JniIdentityHashCode | (Inherited from Object) |
JniPeerMembers | |
PeerReference | (Inherited from Object) |
ThresholdClass |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. |
ThresholdType |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. |
Methods
AddAccount(String, String, String[], Bundle, Activity, IAccountManagerCallback, Handler) |
Asks the user to add an account of a specified type. |
AddAccountExplicitly(Account, String, Bundle, IDictionary<String,Integer>) |
Adds an account directly to the AccountManager. |
AddAccountExplicitly(Account, String, Bundle) |
Adds an account directly to the AccountManager. |
AddOnAccountsUpdatedListener(IOnAccountsUpdateListener, Handler, Boolean, String[]) |
Adds an |
AddOnAccountsUpdatedListener(IOnAccountsUpdateListener, Handler, Boolean) |
Adds an |
BlockingGetAuthToken(Account, String, Boolean) |
This convenience helper synchronously gets an auth token with
|
ClearPassword(Account) |
Forgets a saved password. |
Clone() |
Creates and returns a copy of this object. (Inherited from Object) |
ConfirmCredentials(Account, Bundle, Activity, IAccountManagerCallback, Handler) |
Confirms that the user knows the password for an account to make extra sure they are the owner of the account. |
Dispose() | (Inherited from Object) |
Dispose(Boolean) | (Inherited from Object) |
EditProperties(String, Activity, IAccountManagerCallback, Handler) |
Offers the user an opportunity to change an authenticator's settings. |
Equals(Object) |
Indicates whether some other object is "equal to" this one. (Inherited from Object) |
FinishSession(Bundle, Activity, IAccountManagerCallback, Handler) |
Finishes the session started by |
FromContext(Context) | |
Get(Context) |
Gets an AccountManager instance associated with a Context. |
GetAccounts() |
Lists all accounts visible to the caller regardless of type. |
GetAccountsAndVisibilityForPackage(String, String) |
Gets all accounts of given type and their visibility for specific package. |
GetAccountsByType(String) |
Lists all accounts of particular type visible to the caller. |
GetAccountsByTypeAndFeatures(String, String[], IAccountManagerCallback, Handler) |
Lists all accounts of a type which have certain features. |
GetAccountsByTypeForPackage(String, String) |
Returns the accounts visible to the specified package in an environment where some apps are not authorized to view all accounts. |
GetAccountVisibility(Account, String) |
Get visibility of certain account for given application. |
GetAuthenticatorTypes() |
Lists the currently registered authenticators. |
GetAuthToken(Account, String, Boolean, IAccountManagerCallback, Handler) |
Obsolete.
Gets an auth token of the specified type for a particular account, optionally raising a notification if the user must enter credentials. |
GetAuthToken(Account, String, Bundle, Activity, IAccountManagerCallback, Handler) |
Gets an auth token of the specified type for a particular account, prompting the user for credentials if necessary. |
GetAuthToken(Account, String, Bundle, Boolean, IAccountManagerCallback, Handler) |
Gets an auth token of the specified type for a particular account, optionally raising a notification if the user must enter credentials. |
GetAuthTokenByFeatures(String, String, String[], Activity, Bundle, Bundle, IAccountManagerCallback, Handler) |
This convenience helper combines the functionality of |
GetHashCode() |
Returns a hash code value for the object. (Inherited from Object) |
GetPackagesAndVisibilityForAccount(Account) |
Returns package names and visibility which were explicitly set for given account. |
GetPassword(Account) |
Gets the saved password associated with the account. |
GetPreviousName(Account) |
Gets the previous name associated with the account or |
GetUserData(Account, String) |
Gets the user data named by "key" associated with the account. |
HasFeatures(Account, String[], IAccountManagerCallback, Handler) |
Finds out whether a particular account has all the specified features. |
InvalidateAuthToken(String, String) |
Removes an auth token from the AccountManager's cache. |
IsCredentialsUpdateSuggested(Account, String, IAccountManagerCallback, Handler) |
Checks whether |
JavaFinalize() |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. (Inherited from Object) |
NewChooseAccountIntent(Account, IList<Account>, String[], Boolean, String, String, String[], Bundle) |
Deprecated in favor of |
NewChooseAccountIntent(Account, IList<Account>, String[], String, String, String[], Bundle) |
Returns an intent to an |
Notify() |
Wakes up a single thread that is waiting on this object's monitor. (Inherited from Object) |
NotifyAccountAuthenticated(Account) |
Notifies the system that the account has just been authenticated. |
NotifyAll() |
Wakes up all threads that are waiting on this object's monitor. (Inherited from Object) |
PeekAuthToken(Account, String) |
Gets an auth token from the AccountManager's cache. |
RemoveAccount(Account, Activity, IAccountManagerCallback, Handler) |
Removes an account from the AccountManager. |
RemoveAccount(Account, IAccountManagerCallback, Handler) |
Removes an account from the AccountManager. |
RemoveAccountExplicitly(Account) |
Removes an account directly. |
RemoveOnAccountsUpdatedListener(IOnAccountsUpdateListener) |
Removes an |
RenameAccount(Account, String, IAccountManagerCallback, Handler) |
Rename the specified |
SetAccountVisibility(Account, String, AccountVisibility) |
Set visibility value of given account to certain package. |
SetAuthToken(Account, String, String) |
Adds an auth token to the AccountManager cache for an account. |
SetHandle(IntPtr, JniHandleOwnership) |
Sets the Handle property. (Inherited from Object) |
SetPassword(Account, String) |
Sets or forgets a saved password. |
SetUserData(Account, String, String) |
Sets one userdata key for an account. |
StartAddAccountSession(String, String, String[], Bundle, Activity, IAccountManagerCallback, Handler) |
Asks the user to authenticate with an account of a specified type. |
StartUpdateCredentialsSession(Account, String, Bundle, Activity, IAccountManagerCallback, Handler) |
Asks the user to enter a new password for the account but not updating the
saved credentials for the account until |
ToArray<T>() | (Inherited from Object) |
ToString() |
Returns a string representation of the object. (Inherited from Object) |
UnregisterFromRuntime() | (Inherited from Object) |
UpdateCredentials(Account, String, Bundle, Activity, IAccountManagerCallback, Handler) |
Asks the user to enter a new password for an account, updating the saved credentials for the account. |
Wait() |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>. (Inherited from Object) |
Wait(Int64, Int32) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Wait(Int64) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Events
AccountsUpdated |
Explicit Interface Implementations
IJavaPeerable.Disposed() | (Inherited from Object) |
IJavaPeerable.DisposeUnlessReferenced() | (Inherited from Object) |
IJavaPeerable.Finalized() | (Inherited from Object) |
IJavaPeerable.JniManagedPeerState | (Inherited from Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from Object) |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |