3

I am performing sync in my application for every 12 hours ,earlier i tried in android 4.4 below versions sync adapter is working fine, but kitkat and above periodicsync is not even triggering please help me.

public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) {
    Account account = getSyncAccount(context);
    String authority = context.getString(R.string.content_authority);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // we can enable inexact timers in our periodic sync
        SyncRequest request = new SyncRequest.Builder().
                syncPeriodic(syncInterval, flexTime).
                setSyncAdapter(account, authority).build();
        ContentResolver.requestSync(request);
    } else {
        ContentResolver.addPeriodicSync(account,
                authority, new Bundle(), syncInterval);
    }
}
skyshine
  • 2,767
  • 7
  • 44
  • 84
  • 1
    Did you solve this? I would appreciate any tip – BamsBamx Jun 20 '15 at 11:52
  • I think I found the problem. I had the auto-sync data option turned off. Go Settings->Accounts->[overflow menu]->Auto-sync data – BamsBamx Jun 20 '15 at 12:26
  • And be sure you set 'android:isAlwaysSyncable="true"' in your syncadapter.xml and 'android:syncable="true"' in your provider element of AndroidManifest.xml – BamsBamx Jun 20 '15 at 13:35
  • Starting Android 7 the minimum frequency is 15 min. See here: https://stackoverflow.com/questions/31945718/contentresolver-addperiodicsync-interval-round-up/47409131#47409131 – user3270526 Nov 21 '17 at 09:25

1 Answers1

4

I have solved this question,for kitkat and above we need to write separate code

code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            SyncRequest.Builder b = (new SyncRequest.Builder()).syncPeriodic(syncInterval, flexTime);
            b.setSyncAdapter(account, authority);
            b.setExtras(new Bundle());
            ContentResolver.requestSync(b.build());
        } else {
            ContentResolver.addPeriodicSync(account, authority, new Bundle(),
                    syncInterval);
skyshine
  • 2,767
  • 7
  • 44
  • 84