I want to use sync adapter for calling a method once per day. As I do not need Content Provider
, I defined a dummy provider just to make sync adapter work. The problem is that sync trigger about every 10 minutes, no matter what I set for time and never trigger on some devices. How can I make it work on all devices at exact time?
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);
SyncAdapter:
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
ContentProviderClient provider, SyncResult syncResult) {
Log.e("sync", "sync successful");
}
Maybe a workaround if this is urgent for you:
If your account is also just a dummy (as it seems), you can use AlarmManager instead of the sync adapter pattern. You then don't need the dummy content provider and so on. You can set a timer - when to call a message or whatever - on the AlarmManager then.
Note that you don't have the sync android system features if you use an AlarmManager.