我使用PeriodicWorkRequest
创建了定期请求。它适用于所有期望MI,OPPO和VIVO的设备。
private var mPeriodicWorkRequest: PeriodicWorkRequest? = null
mPeriodicWorkRequest = PeriodicWorkRequest
.Builder(MyPeriodicWork::class.java, 30, TimeUnit.MINUTES,15, TimeUnit.MINUTES)
.addTag("periodicWorkRequest")
.build()
WorkManager.getInstance().enqueue(mPeriodicWorkRequest!!)
MyPeriodicWork类---
class MyPeriodicWork(workerParams: WorkerParameters?) : Worker( workerParams!!) {
override fun doWork(): Result {
Log.e(TAB, "PeriodicWork in BackGround")
return Result.success()
}
}