Android同步适配器-手动同步
我正在尝试创建一个同步适配器,持续数小时 同步设置始终处于停用状态。为什么? 雄激素单Android同步适配器-手动同步,android,adapter,sync,Android,Adapter,Sync,我正在尝试创建一个同步适配器,持续数小时 同步设置始终处于停用状态。为什么? 雄激素单 <provider android:name="com.example.authenticating.DataProvider" android:authorities="@string/content_authority" android:exported="false" android:multiprocess="true"
<provider
android:name="com.example.authenticating.DataProvider"
android:authorities="@string/content_authority"
android:exported="false"
android:multiprocess="true"
android:syncable="true" />
<service
android:name="com.example.authenticating.AuthenticatationService"
android:exported="true"
android:process=":auth">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
如果要执行手动同步,必须调用:
Bundle settings = new Bundle();
settings.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
settings.putBooleanContentResolver.SYNC_EXTRAS_EXPEDITED, true);
ContentResolver.requestSync(mAccount, AUTHORITY, settingsBundle);
如果要启用同步适配器,则需要将“自动同步”设置为true,即:
ContentResolver.setSyncAutomatically(mAccount, AUTHORITY, true);
这将在您的帐户下设置检查,并使同步适配器能够在设备遇到网络问题时运行(请参阅)
确保向清单添加以下权限:
android.permission.WRITE_SYNC_SETTINGS
文档中没有明确说明这一点,但据我所知,即使您没有将同步适配器“启用”为“自动同步”,它仍然可以使用您在其上设置的手动同步或定期同步
ContentResolver.setSyncAutomatically(mAccount, AUTHORITY, true);
android.permission.WRITE_SYNC_SETTINGS