I incidentally abstractaccountauthenticator also translated, feel directly to see the samplesyncadapter example is difficult to quickly understand the overall intent, with the API is a good way to sigh the Android API this is too detailed.
Abstractaccountauthenticator Overview
Abstractaccountauthenticator Overview
This is an abstract base class for creating the Account Manager (Accountauthenticators). In order to become an authenticator, a class must inherit the class, provide an implementation of the abstract method, and write a service,
When called by the Action_authenticator_intent as Action Intent, in the Onbind (android.content.Intent) method implementation of the service, return directly to Getibinder () The result of the return value. In
Androidmanifest.xml file, this service must specify the following intent filter (intent filter) and metadata token.
<intent-filter>
<action android:name= "Android.accounts.AccountAuthenticator"/>
</intent-filter>
<meta-data android:name= "Android.accounts.AccountAuthenticator"
Android:resource= "@xml/authenticator"/>
Translator Note: Action_authenticator_intent is actually a constant, equal to the string android.accounts.AccountAuthenticator, in fact, and above this intent Filter action is the same.
In the XML description above, the Android:resource property must point to a resource file, as follows:
<account-authenticator
Xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:accounttype= "Typeofauthenticator"
android:icon= "@drawable/icon"
android:smallicon= "@drawable/miniicon"
Android:label= "@string/label"
android:accountpreferences= "@xml/account_preferences"
/>
Replace the value pointed to by the icon and the Label property with your own resource. The Android:accounttype property must be a string that uniquely identifies your authenticator and is used when the user uses Accountmanager
The specified string is the same and is consistent with your account type. A user of Android:icon is on the "Account and Sync" Settings page, and a user of Android:smallicon is in the contact
The label panel for the application.
android:accountpreferences property points to an XML configuration file (Preferencescreen XML) for a preference screen setting. It contains a list of preferencescreen that can be nested hierarchically.
<preferencescreen
xmlns: Android= "Http://schemas.android.com/apk/res/android";
< Preferencecategory android:title= "@string/title_fmt"/>
< Preferencescreen
android:key= "Key1"
android:title=" @string/key1_action "
android:summary= "@string/key1_summary";
<intent
android:action= "Key1. ACTION "
android:targetpackage=" Key1.package "
android:targetclass= "Key1.class"/>
</PreferenceScreen>
</preferencescreen>
A standard implementation pattern for some abstract methods, like this:
- * If the parameters provided for the authenticator are sufficient to reach full satisfaction, then this will be done and return a bundle containing the results.
- * If the authenticator needs to collect information from the user to be satisfied, a intent will be created to open "activity prompting user information" and complete the request. This INTENT must return a Bundle containing the specified KEY name called Key_intent. When finished, the activity needs to return the result of the final adornment.
This intent should use KEY to indicate key_account_manager_response to contain accountauthenticatorresponse. This activity must be called Onresult (Bundle) or onError (int, String) at the end.
- If the authenticator cannot process the request synchronously and returns a result. Then when the request is completed, it can choose to return null and use Accountmanagerresponse to send the result.
Subsequent descriptions of each of the abstract authenticator methods will not describe the possible asynchronous native request processing, but instead describe the input parameters and expected results.
When writing an activity to satisfy those requests, one way must be when the activity is closed (or in any other case the author of the activity thinks it is the right time to respond), by Accountmanagerresponse and returning the result through a response. Accountauthenticatoractivity is used to handle these, and when writing activity to handle these requests, someone can wish to inherit (extend) it.
-----
Yunfei Zhang Vir written in 2014-10-15
Android Chinese Translation-Abstractaccountauthenticator overview