Share via


AccountManager.AddAccount Method

Definition

Asks the user to add an account of a specified type.

[Android.Runtime.Register("addAccount", "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Landroid/os/Bundle;Landroid/app/Activity;Landroid/accounts/AccountManagerCallback;Landroid/os/Handler;)Landroid/accounts/AccountManagerFuture;", "GetAddAccount_Ljava_lang_String_Ljava_lang_String_arrayLjava_lang_String_Landroid_os_Bundle_Landroid_app_Activity_Landroid_accounts_AccountManagerCallback_Landroid_os_Handler_Handler")]
[Android.Runtime.RequiresPermission("android.permission.MANAGE_ACCOUNTS")]
public virtual Android.Accounts.IAccountManagerFuture? AddAccount (string? accountType, string? authTokenType, string[]? requiredFeatures, Android.OS.Bundle? addAccountOptions, Android.App.Activity? activity, Android.Accounts.IAccountManagerCallback? callback, Android.OS.Handler? handler);
[<Android.Runtime.Register("addAccount", "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Landroid/os/Bundle;Landroid/app/Activity;Landroid/accounts/AccountManagerCallback;Landroid/os/Handler;)Landroid/accounts/AccountManagerFuture;", "GetAddAccount_Ljava_lang_String_Ljava_lang_String_arrayLjava_lang_String_Landroid_os_Bundle_Landroid_app_Activity_Landroid_accounts_AccountManagerCallback_Landroid_os_Handler_Handler")>]
[<Android.Runtime.RequiresPermission("android.permission.MANAGE_ACCOUNTS")>]
abstract member AddAccount : string * string * string[] * Android.OS.Bundle * Android.App.Activity * Android.Accounts.IAccountManagerCallback * Android.OS.Handler -> Android.Accounts.IAccountManagerFuture
override this.AddAccount : string * string * string[] * Android.OS.Bundle * Android.App.Activity * Android.Accounts.IAccountManagerCallback * Android.OS.Handler -> Android.Accounts.IAccountManagerFuture

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
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
IAccountManagerCallback

Callback to invoke when the request completes, null for no callback

handler
Handler

Handler identifying the callback thread, null for the main thread

Returns

An AccountManagerFuture which resolves to a Bundle with these fields if activity was specified and an account was created: <ul> <li> #KEY_ACCOUNT_NAME - the name of the account created <li> #KEY_ACCOUNT_TYPE - the type of the account </ul>

        If no activity was specified, the returned Bundle contains only
        <code data-dev-comment-type="c">#KEY_INTENT</code> with the <code data-dev-comment-type="c">Intent</code> needed to launch the
        actual account creation process.  If an error occurred,
        <code data-dev-comment-type="c">AccountManagerFuture#getResult()</code> throws:
        &lt;ul&gt;
        &lt;li&gt; <code data-dev-comment-type="c">AuthenticatorException</code> if no authenticator was registered for
             this account type or the authenticator failed to respond
        &lt;li&gt; <code data-dev-comment-type="c">OperationCanceledException</code> if the operation was canceled for
             any reason, including the user canceling the creation process or adding accounts
             (of this type) has been disabled by policy
        &lt;li&gt; <code data-dev-comment-type="c">IOException</code> if the authenticator experienced an I/O problem
             creating a new account, usually because of network trouble
        &lt;/ul&gt;
Attributes

Remarks

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.

<b>NOTE:</b> 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.

Java documentation for android.accounts.AccountManager.addAccount(java.lang.String, java.lang.String, java.lang.String[], android.os.Bundle, android.app.Activity, android.accounts.AccountManagerCallback<android.os.Bundle>, android.os.Handler).

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.

Applies to