【发布时间】:2017-08-21 14:04:44
【问题描述】:
我有一个自定义帐户、SyncAdapter 和相应的服务等设置,并且在模拟器(Nexus 5X API 25)上运行良好。我目前只是尝试手动调用 onPerformSync 进行测试和理解,所以我使用以下代码 -
Account acct = getMyAccount() ;
Bundle bundle = new Bundle();
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
if(permissionsHelper.canDoCalendar()){
ContentResolver.requestSync(acct, "com.android.calendar", bundle);
}else{
Log.e(LOG_TAG, "Permissions not yet granted..Wont start syncadatper") ;
}
此代码适用于模拟器,但不适用于我的真实手机。 ContentResolver.requestSync 被调用,但在那之后,什么也没有发生。我可以在模拟器上使用调试器,但物理设备上的调试器在 requestSync 之后无法工作,我也没有看到任何错误或堆栈跟踪 - 我一直在查看没有任何过滤器的日志,以确保我不会错过日志由其他进程发出(尽管模拟器不会在不同的进程中运行adatper)。我没有在 adatper 服务配置中提供 android:process 选项。
使用 targetSDK 25
服务配置:
<service
android:name=".core.calendar.SyncAdapterService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/calendar_syncadapter" />
</service>
SyncAdatper 配置
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="com.android.calendar"
android:accountType="xxxxxx" <-- removed for the time from post
android:userVisible="true"
android:allowParallelSyncs="false"
android:isAlwaysSyncable="true"
android:supportsUploading="false"
/>
【问题讨论】:
标签: android android-syncadapter