【发布时间】:2016-12-19 07:29:43
【问题描述】:
我想使用同步适配器每天调用一次方法。因为我不需要Content Provider,所以我定义了一个虚拟提供程序,只是为了让同步适配器工作。问题是同步触发大约每 10 分钟一次,无论我设置什么时间,并且永远不会在某些设备上触发。我怎样才能让它在准确的时间在所有设备上工作?
final Account account = new Account(username, "com.example.shop");
Bundle userData = new Bundle();
accountManager.addAccountExplicitly(account, "", userData);
// initial sync adapter
String AUTHORITY = "com.example.shop.syncAdapter.DummyProvider";
ContentResolver.setIsSyncable(account, AUTHORITY, 1);
ContentResolver.setSyncAutomatically(account, AUTHORITY, true);
ContentResolver.addPeriodicSync(account, AUTHORITY, Bundle.EMPTY, 86400);
同步适配器:
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
ContentProviderClient provider, SyncResult syncResult) {
Log.e("sync", "sync successful");
}
【问题讨论】:
标签: android android-syncadapter