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