Accountmanager usage tutorial

Source: Internet
Author: User

API explanation

This class provides users with an interface for centralized account injection. You only need to enter the account password once before you can ask for Internet resources.

Different online services manage users in different ways. Therefore, account manager provides a unified authentication management method for different types of accounts to process valid account information and sort the information. Google, Facebook, and Microsoft Exchange have their own verification methods.

Many servers support some verification algorithms and do not need to send the user password to verify the correctness. Accountmanager can generate a tokens for the application, so that the application does not need to directly process the password. Tokens can be reused and cached by accountmanager, but must be refreshed periodically. The application must discard tokens when it stops working so that the accountmanager knows that tockens needs to be generated again.

 

Steps for using accountmanager: (example of carrrimail code)

First, obtain the accountmanager instance.

Accountmanager. Get (context)

 

Second, useGetaccountsbytype (string)Or getaccountsbytypeandfeatures (string, string [], accountmanagercallback, Handler) to obtain available accounts

Account [] accounts = accountmanager. Get (context). getaccountsbytype (
"Com. Google ");

// In carrimail, You need to obtain the Gmail account and input "com. Google" here"

 

Third, if the application uses a previously remembered account information, make sure that this account is in the result set returned by getaccountsbytype (string, if an account that is no longer on the device is used, an undefined exception is thrown.

 

Fourth, when getauthtoken (account, String, bundle, activity, accountmanagercallback, Handler) or other methods are used to obtain the auth token of the selected account, view the relevant documentation to learn the exact usage and troubleshooting methods.

 

Fifth, assume that the request fails and an authentication error is reported. This is because the cached auth token has expired. You must call the invalidateauthtoken (string, string) method.

Traverse the obtained accounts information

For (account Account: Accounts ){
String name = Account. Name; // your region has been successfully renewed
// Google Translate into memory
// Omitted here

}

Accountmanager usage tutorial

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.