我已使用同步适配器进行数据同步,并在5分钟间隔内进行了定期同步的代码,但是在Android OS版本8和9&mi设备上未按此间隔调用onPerformSync()方法。我也测试了棉花糖设备中的相同代码,并且在棉花糖中工作正常。
我已经从设置中手动启用了自动同步。然后尝试检查自动同步是否正常。
public void setSyncPeriodic(String authority, long interval_in_minute,
long seconds_per_minute, long milliseconds_per_second) {
Account account = mUser.getAccount();
Bundle extras = new Bundle();
this.setAutoSync(authority, true);
ContentResolver.setIsSyncable(account, authority, 1);
final long sync_interval = interval_in_minute * seconds_per_minute
* milliseconds_per_second;
int flexTime = (int) (sync_interval/3);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// we can enable inexact timers in our periodic sync
SyncRequest request = new SyncRequest.Builder()
.syncPeriodic(sync_interval, flexTime)
.setSyncAdapter(account, authority)
.setExtras(new Bundle()).build();
ContentResolver.requestSync(request);
} else {
ContentResolver.addPeriodicSync(account, authority, new Bundle(), sync_interval);
}
/*ContentResolver.addPeriodicSync(account, authority, extras,
sync_interval);*/
}
请指导我如何使用同步适配器为所有设备和所有android os版本实现自动同步。