Reputation: 2864
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);
}
}
Upvotes: 3
Views: 1036
Reputation: 2864
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);
Upvotes: 4