I have tried the great Google example to sync contact from a webservice and that work fine. This is called the SampleSyncAdapter and really worth it: http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
I succed everything, but I cannot found in the example nor in the documentation a way to add a category that would link to a custom activity, exactly like the screenshot below:
(I have only the sync account option with the checkbox)
So, my question is: how can I add the account settings category?
herschel's answer provides a link to a generic solution. Here's how to modify the SampleSyncAdapter source to add custom preferences (Android 2.3.4) that look like the screenshot above:
Remember that the account manager is running as a system process, so the phone will crash if there's an unhandled exception in your code, a missing manifest entry, or an error in your xml.
Create an
account_preferences.xml
resource file.android:key
value must be specified as"account_settings"
.PreferenceCategory
tag when you define it; if you put thePreferenceScreen
inside the category the phone will crash when you click on the preference.XML:
Add a reference to
account_preferences.xml
at the end ofauthenticator.xml
:Create a preference activity and add it to the manifest. I used a simplified version of the sample code from the answer to How do we control an Android sync adapter preference?.
a. Add the activity to the manifest:
b. Here's the most trivial
AccountPreferences.java
:c. Here's
preferences_resources.xml
with hard-coded strings:That's it. Install your code, open the accounts, and select your SampleSyncAdapter account (user1). Select Account Settings and you see the settings activity.
Custom sync preferences http://i49.tinypic.com/5d6ve0.jpg