【问题标题】:Android sync adapter trigger every 10 minutesAndroid 同步适配器每 10 分钟触发一次
【发布时间】: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


    【解决方案1】:

    如果这对您来说很紧急,也许是一个解决方法

    如果您的帐户也只是一个虚拟帐户(看起来如此),您可以使用 AlarmManager 代替同步适配器模式。然后,您就不需要虚拟内容提供者等。然后,您可以在 AlarmManager 上设置 timer - 何时调用消息或其他任何内容。

    请注意,如果您使用 AlarmManager,则没有同步 android 系统功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      相关资源
      最近更新 更多