Error in performing periodic sync
Asked Answered
B

1

6

I am trying to perform a period sync using a sync adapter. It syncs fine manually but not periodically. This is the only thing I got from logcat

Could not find class 'android.content.SyncRequest$Builder', referenced from method 
com.example.user.sunshine.sync.SunshineSyncAdapter.configurePeriodicSync

Below is my code:

 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) {
        SyncRequest request = new SyncRequest.Builder().
                syncPeriodic(syncInterval, flexTime).
                setSyncAdapter(account, authority).build();
        ContentResolver.requestSync(request);
    } else {
        ContentResolver.addPeriodicSync(account,
                authority, new Bundle(), syncInterval);
    }
}

Does anyone know why this happens and how I should go about resolving it?

Blackandblue answered 11/9, 2014 at 12:58 Comment(0)
B
-2

This error appears if your testing in devices not running KitKat and above . I bet, it has not problem in Kitkat and above as the appropriate android classes would be compiled into the apk.

I suggest you don't worry about, if your testing on lower devices , because of this portion of your code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        SyncRequest request = new SyncRequest.Builder().
                syncPeriodic(syncInterval, flexTime).
                setSyncAdapter(account, authority).build();
        ContentResolver.requestSync(request);
    } else {
        ContentResolver.addPeriodicSync(account,
                authority, new Bundle(), syncInterval);
    }

Also try checking the export button for android 4.4.* in the build libraries

Bung answered 29/4, 2015 at 9:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.