我正在尝试让自定义 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 日志记录,说明帐户已设置为可同步,因此该方法未执行任何操作。
然而,提供商拒绝出现在“设置”>“帐户与同步”>“数据与同步”中。关于为什么的任何想法?任何人都知道它是如何确定该部分中显示的内容的?
[编辑]更多信息:
在调试了几个小时之后,我遇到了这个错误:
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 类实际上从未被调用过。我应该自己调用它吗?我见过的示例或野外的应用程序都没有自己调用它,但它们也都有 auth 组件。想法?
最佳答案
<meta-data android:name="android.content.SyncAdapater"
android:resource="@xml/syncadapter" />
有没有其他人注意到答案?
天哪,我讨厌当个白痴。
关于android - ContentProvider 不会出现在 Data & Synchronization 区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5619101/