您正在尝试建立一个没有约束的工作,这是不允许的 java.lang.IllegalArgumentException
You're trying to build a job with no constraints, this is not allowed java.lang.IllegalArgumentException
我的应用程序在 29 及以上运行良好,但在 29 以下我收到此错误,我不想使用任何约束是他们以任何方式解决此问题而不使用约束
private fun scheduleService(sms: Sms) {
Log.i("JobID","${sms.messages.messageId.toInt()}")
val jobScheduler= requireContext().getSystemService(AppCompatActivity.JOB_SCHEDULER_SERVICE) as JobScheduler
val serializedSms = GsonUtils.serializeSms(sms)
val componentName = ComponentName(requireContext() , TodoJobService::class.java)
val jobInfo = JobInfo.Builder(sms.messages.messageId.toInt() ,componentName)
jobInfo.setPersisted(true )
val persistableBundle = PersistableBundle()
persistableBundle.putString(TodoJobService.JOB_KEY,serializedSms)
jobInfo.setExtras(persistableBundle)
jobScheduler.schedule(jobInfo.build())
}
Prior to Android version Build.VERSION_CODES#Q
, you had to specify at least one constraint on the JobInfo object that you are creating. Otherwise, the builder would throw an exception when building. From Android version Build.VERSION_CODES#Q
and onwards, it is valid to schedule jobs with no constraints.
你不能只设置一个无关紧要的约束吗?较低的最低限度,您喜欢的退避政策,诸如此类
我的应用程序在 29 及以上运行良好,但在 29 以下我收到此错误,我不想使用任何约束是他们以任何方式解决此问题而不使用约束
private fun scheduleService(sms: Sms) {
Log.i("JobID","${sms.messages.messageId.toInt()}")
val jobScheduler= requireContext().getSystemService(AppCompatActivity.JOB_SCHEDULER_SERVICE) as JobScheduler
val serializedSms = GsonUtils.serializeSms(sms)
val componentName = ComponentName(requireContext() , TodoJobService::class.java)
val jobInfo = JobInfo.Builder(sms.messages.messageId.toInt() ,componentName)
jobInfo.setPersisted(true )
val persistableBundle = PersistableBundle()
persistableBundle.putString(TodoJobService.JOB_KEY,serializedSms)
jobInfo.setExtras(persistableBundle)
jobScheduler.schedule(jobInfo.build())
}
Prior to Android version
Build.VERSION_CODES#Q
, you had to specify at least one constraint on the JobInfo object that you are creating. Otherwise, the builder would throw an exception when building. From Android versionBuild.VERSION_CODES#Q
and onwards, it is valid to schedule jobs with no constraints.
你不能只设置一个无关紧要的约束吗?较低的最低限度,您喜欢的退避政策,诸如此类