I'm trying to get a custom ContentProvider to show up under Data & synchronization, and I'm running into some problems. Namely, it's not showing up.
The specifics:
My AndroidManifest.xml has the provider and service:
<provider android:name="BooksProvider"
android:label="ClientName Books"
android:authorities="com.clientname.reader.books"
android:enabled="true"
android:exported="true"
android:syncable="true">
<grant-uri-permission android:pathPattern=".*" />
</provider>
<service android:name=".sync.SyncService"
android:exported="true" android:process=":sync">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data android:name="android.content.SyncAdapater"
android:resource="@xml/syncadapter" />
</service>
And res/xml/syncadapter.xml has the following:
<?xml version="1.0" encoding="utf-8"?>
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="com.clientname.reader.books"
android:accountType="com.google"
android:supportsUploading="true"
android:userVisible="true"
/>
Just to be safe, I've even called the following on onCreate:
AccountManager accountManager = AccountManager.get(getApplicationContext());
Account[] accounts = accountManager.getAccountsByType("com.google");
for(Account account : accounts){
Log.d(TAG, "Account: " + account.name);
ContentResolver.setIsSyncable(account, Reader.AUTHORITY, 1);
}
When I load up the Activity, I get adb logging from ContentResolver.setIsSyncable saying that account is already set to be syncable, so the method isn't doing anything.
And yet, the provider refuses to show up in Settings > Accounts & Sync > Data & synchronization. Any ideas on why? Anyone know how it's determined what appears in that section?
[edit] Some more information:
After spending hours debugging, I'm coming across this error:
04-11 10:46:02.370: DEBUG/SyncManager(105): can't find a sync adapter for SyncAdapterType Key {name=com.clientname.reader.books, type=com.google}, removing settings for it
It also appears my SyncService class is never actually getting called. Am I supposed to be invoking it myself? None of the samples I've seen or applications in the wild invoke it themselves, but they also all have auth components. Thoughts?
Does anyone else notice the answer?
God, I hate being an idiot.
As I finally figured out, another reason why the ContentProvider might not be showing up under the Synchronization Settings screen is because of a missing android.permission.WRITE_SYNC_SETTINGS permission in the Manifest. Unfortunately all tutorials, articles, and documentation I've read misses this point or is not explicitly outlined. Furthermore, the platform (tested under API level 13) does not appear to throw any form of permission exception - I hope they fix this. Hopefully this helps someone.
So from a semantics perspective, Providers do not show up directly in Accounts & Sync. Instead, Accounts show up, with providers on their detail pages. So since you're binding your SyncAdapter to a com.google style account, the sync adapater will show up within your google account -- alongside "contacts" and "Calendar" and "Gmail", you should see "ClientName Books"
However, your real problem is your XML. Per AndroidManifest.xml docs,
So, it looks like it's not finding your
BooksProvider
class because it needs the FQCN or relative path through your packages.