Android Chinese Translation-Accountmanager overview

Source: Internet
Author: User

in order to understand, I translated the overview section of the Accountmanager class. Reprint Please specify source: http://www.cnblogs.com/vir56k/p/4025722.html Accountmanager Overview
This class provides the ability to access a centralized registry of users ' online accounts. The user enters authentication information for each account (credentials, which contains the user name and password), and clicks once (one-click) to complete the authentication, authorizing the application (app) to access the online resources. Different services have different ways of processing account authentication, and account Manager uses a plug-in authenticator module to correspond to different types of accounts. The authenticator, which is written by a third-party organization, processes the actual content of the authentication information for the account. and save the account information. For example, Google, Facebook, and Microsoft each have their own authenticator. 

Many services support the concept of a single authorization token (authentication token, abbreviated as AUTH token), which is often used to verify authorization requests that are issued to the service that do not contain a real password. Auth tokens are often created in separate requests that contain user authentication information (user name and password). Accountmanager can generate authentication tokens (auth tokens) for an application, then the application does not need to process the password directly. Autho tokens are often reusable and accountmanager cached, but must be refreshed periodically. When you stop working, the application makes Auth tokens invalid so that Auth tokens knows to regenerate them. The application access service typically passes through the following steps:

    The
    • obtains an instance of Auccountmanager through the Get (Context) method.
    • lists the available accounts, using Getaccountsbytype (String) or Getaccountsbytypeandfeatures (string, string[], Accountmanagercallback, Handler). A generic application is interested in an account of a specified type, which is the identifier of the authenticator. Account attributes are used to identify the subtype and ability of a particular account. Account types and attributes these are the authenticator specification strings and must be known by the application to coordinate their preferred authenticator.
    • Select one or more available accounts and, if possible, ask the user for their preferences. If no matching account can be used, AddAccount (string, String, string[], Bundle, Activity, Accountmanagercallback, Handler) will be called, Prompt the user to create an appropriate type of account
    • Important: If the app is using the pre-remembered account option, it must ensure that the account still exists in a list of accounts that are returned by Getaccountsbytype (String). Requesting an authentication token for an account no longer causes an "undefined failure" in the device results. The
    • builds the request with Auth token. The Auth token form, the requested format, and the protocol used are specific to the service you want to access. Apps can use any network and protocol libraries.
    • Important: If the request fails with an "authorization error", then the cached auth token may expire and no longer be trusted by the server. The app must call Invalidateauthtoken (String, String) to remove the Auth token's cache, and the request will continue to fail! After making auth token invalid, return immediately to the "Request a Auth token" step above. If the second out process fails, then it will be treated as an honest authentication failure and notify the user or do other appropriate processing.

Some Accountmanager methods may need to interact with the user, prompt the user for authentication information, render options, or ask the user to add an account. The caller can choose whether to allow Accountmanager to start the necessary user interface directly and wait for the user, or to return a intent, which is the caller can start the interface. Or in some cases, install a notification that the user can choose to go to start the interface. Let Accountmanager start the interface directly, the caller must provide the context of the activity at the current front end.

Many Accountmanager methods use Accountmanagercallback and handler as parameters. These methods return immediately and start asynchronously. If a callback is provided, then run (accountmanagerfuture) will be called on the handler thread. The result is re-obtained through the GetResult () method of the "return value" Accountmanagerfuture (also available through the callback method). This method waits for the operation to complete (if necessary) and either: Returns the result or throws an exception during the operation. For the request to be executed synchronously, the GetResult () is called immediately after the method receives the future, and no callback is required.

Requests may be blocked, including GetResult (), and must be guaranteed to never be invoked on the main thread. If the main thread is used, those operations will throw a IllegalStateException exception.

****************************************************************************************

Common methods of Accountmanager

Set a password for the specified account
Maccountmanager.setpassword (account, Mpassword);

Add account to Account Center
Final Account Account = new Account (Musername, constants.account_type);
maccountmanager.addaccountexplicitly (account, Mpassword, null);

Get Authtoken
Final String Authtoken = Maccountmanager.blockinggetauthtoken (account,
Constants.authtoken_type, notify_auth_failure);

Get User Data
String markerstring = maccountmanager.getuserdata (account, Sync_marker_key);

Android Chinese Translation-Accountmanager overview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.