0

I am running a periodic work manager it is not able to work in android 8, 9 & 10. But it works fine in older versions.

Work Manager tested in Nokia 6 And One plus 7T and Moto g5 plus.

Work Manager Version used

implementation "androidx.work:work-runtime:2.2.0"
compileSdkVersion 29
buildToolsVersion "29.0.3"

defaultConfig {
    applicationId "com.example.myApp"
    minSdkVersion 21
    targetSdkVersion 29

Proguard Rules

-keep class * extends androidx.work.Worker -keep class * extends androidx.work.InputMerger

-keep public class * extends androidx.work.ListenableWorker { public (...); }

-keep class androidx.work.WorkerParameters

I also have tried a newer version but that also not work properly.

 public void setWorker() {
        Constraints constraints = new Constraints.Builder()
                .setRequiredNetworkType(NetworkType.CONNECTED)
                .build();
        PeriodicWorkRequest myWork = new PeriodicWorkRequest.
                        Builder(MyWorker.class,
                        15, TimeUnit.MINUTES, 5, TimeUnit.MINUTES)
                        .addTag("app_periodic")
                        .setConstraints(constraints).build();
    
        try {
            WorkManager.getInstance(MyApplication.this)
                    .enqueueUniquePeriodicWork("app_worker_notify", 
                     ExistingPeriodicWorkPolicy.KEEP, myWork);

        } catch (IllegalStateException e) {
            e.printStackTrace();
        }
    }
Ravi Parmar
  • 968
  • 11
  • 28

0 Answers0