我试图让自定义 ContentProvider 显示在“数据和同步”下,但遇到了一些问题。也就是说,它没有出现。
具体内容:
我的 AndroidManifest.xml 有提供者和服务:
<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>
res/xml/syncadapter.xml 有以下内容:
<?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"
/>
为了安全起见,我什至在 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);
}
当我加载 Activity 时,我从 ContentResolver.setIsSyncable 获取 adb 日志记录,表明该帐户已设置为可同步,因此该方法没有执行任何操作。
然而,提供商refuses显示在“设置”>“帐户和同步”>“数据和同步”中。有什么想法吗?有人知道如何确定该部分中出现的内容吗?
[编辑]更多信息:
经过几个小时的调试后,我遇到了这个错误:
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
看来我的 SyncService 类实际上从未被调用。我应该自己调用它吗?我见过的示例或野外应用程序都没有调用它本身,但它们也都具有身份验证组件。想法?