AkshayHadapad

MAinativity

Mar 23rd, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package com.example.workmanager;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import androidx.work.Constraints;
  5. import androidx.work.NetworkType;
  6. import androidx.work.PeriodicWorkRequest;
  7. import androidx.work.WorkManager;
  8.  
  9. import android.os.Bundle;
  10.  
  11. import java.util.concurrent.TimeUnit;
  12.  
  13. public class MainActivity extends AppCompatActivity {
  14.  
  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.activity_main);
  19.  
  20.         Constraints constraints=new Constraints.Builder()
  21.                 .setRequiresDeviceIdle(true)
  22.                 .setRequiresCharging(true)
  23.                 .setRequiresBatteryNotLow(true)
  24.                 .build();
  25.  
  26.         PeriodicWorkRequest periodicWorkRequest=new PeriodicWorkRequest.Builder(MyWork.class,16, TimeUnit.MINUTES)
  27.                 .addTag("Periodic")
  28.                 .setConstraints(constraints)
  29.                 .build();
  30.  
  31.         WorkManager.getInstance(this).enqueue(periodicWorkRequest);
  32.     }
  33. }
Add Comment
Please, Sign In to add comment