Error during periodic synchronization

I am trying to perform period synchronization using a synchronization adapter. Synchronization is performed 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 is happening and how I should solve it?

+6
source share
1 answer

This error appears if your testing on devices does not work KitKat and higher. I bet this is not a problem in Kitkat or higher, since the corresponding android classes will be compiled in apk.

I suggest you not to worry if you are testing on lower devices, because of this part 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 build libraries

-1
source

Source: https://habr.com/ru/post/975132/


All Articles