authentication – Android SyncAdapter using a google account-ThrowExceptions

Exception or error:

I have written a SyncAdapter that takes a “” account and performs a sync with an appengine web service. Testing this with the dev tools sync tester (on the emulator), this sync appears to work just fine.

The problem is, it’s not syncing by default. And going to the account in “accounts & sync” shows my google account to be blank – as if there’s no sync services available.

I suspect that in order to get my sync shown in the “accounts & sync” menu, I’d need to implement my own AccountAuthenticator that would do exactly the same thing as what I presume google’s AccountAuthenticator must already do. This is not an exciting job, and it seems very unnecessary. So:

  • is there a way to add an entry to the “accounts & sync” menu that uses my SyncAdapter but relies on a google account? or to add a sub-menu to google accounts that enables sync of my appengine service?

if not,

  • is there a way I can re-use google’s AccountAuthenticator from within an AccountAuthenticator I write?
How to solve:

So it turns out you can have a syncAdapter that uses a “” account, but this requires you write a matching ContentProvider. For example, in AndroidManifest.xml:

<service android:name=".sync.SyncAdapterService" android:exported="true" android:process=":contacts">
    <action android:name="android.content.SyncAdapter" />
  <meta-data android:name="android.content.SyncAdapter" android:resource="@xml/syncadapter" />

and in syncadapter.xml:

<?xml version="1.0" encoding="utf-8"?>
<sync-adapter xmlns:android=""

You then must have a ContentProvider with authority “” in order for android to associate that sync action with your application. Once you have this (it doesn’t even need to do anything meaningful, just exist), your program can appear inside the “accounts & Sync” setting panel – within your chosen google account.

As an additional piece of work, you may need to call:

ContentResolver.setIsSyncable(account, "", 1)

with account as the Account object you want to use for your sync credentials.

Leave a Reply

Your email address will not be published. Required fields are marked *