我正在尝试实现Google IO中讨论的内容提供商同步适配器模式- 幻灯片26.我的内容提供商正在工作,当我从Dev Tools Sync Tester应用程序触发它时,我的同步工作,但是当我调用ContentResolver时.来自我的ContentProvider的requestSync(帐户,权限,捆绑),我的同步永远不会被触发.
ContentResolver.requestSync(
account,
AUTHORITY,
new Bundle());
Run Code Online (Sandbox Code Playgroud)
编辑 - 添加的清单片段我的清单xml包含:
<service
android:name=".sync.SyncService"
android:exported="true">
<intent-filter>
<action
android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter" />
</service>
Run Code Online (Sandbox Code Playgroud)
- 编辑
与我的同步服务关联的syncadapter.xml包含:
<?xml version="1.0" encoding="utf-8"?>
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="AUTHORITY"
android:accountType="myaccounttype"
android:supportsUploading="true"
/>
Run Code Online (Sandbox Code Playgroud)
不确定其他代码会有用.传递给requestSync的帐户是"myaccounttype",传递给调用的AUTHORITY与我的syc适配器xml匹配.
ContentResolver.requestSync是否是请求同步的正确方法?看起来同步测试工具直接绑定到服务并调用启动同步,但这似乎违背了与同步架构集成的目的.
如果这是请求同步的正确方法,那么同步测试器为什么会工作,而不是我对ContentResolver.requestSync的调用?我需要在捆绑中传递一些东西吗?
我正在运行2.1和2.2的设备上的模拟器中进行测试.