Android onStartJob未在API 30上被调用
我有一个要求,在安装apk之后,但在应用程序首次启动之前,在android TV上创建一个频道。所以,一旦安装了apk,我需要运行一段代码在设备上创建通道 为此,我编写了一个安排Jobservice的接收器Android onStartJob未在API 30上被调用,android,android-jobscheduler,Android,Android Jobscheduler,我有一个要求,在安装apk之后,但在应用程序首次启动之前,在android TV上创建一个频道。所以,一旦安装了apk,我需要运行一段代码在设备上创建通道 为此,我编写了一个安排Jobservice的接收器 class MyIntentReceiver: BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { NotificationJobService.
class MyIntentReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
NotificationJobService.schedule(context!!)
}
}
class NotificationJobService : JobService() {
companion object {
fun schedule(context: Context) {
val jobService = ComponentName(context, NotificationJobService::class.java)
val jobInfo = JobInfo.Builder(501, jobService)
.setMinimumLatency(0)
.setOverrideDeadline(0)
.build()
val result = (context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler) .schedule(jobInfo)
Log.d("DEBUG_TAG", "Job scheduled with. $result")
}
}
override fun onStartJob(params: JobParameters?): Boolean {
Log.d("DEBUG_TAG", "onStartJob Called.")
return true
}
override fun onStopJob(params: JobParameters?): Boolean {
Log.d("DEBUG_TAG", "onStopJob Called.")
return true
}
}
这段代码在安卓27、28上的效果与预期一样。i、 e安装apk后(首次启动应用程序之前),如果我使用此命令
adb shell am broadcast -a android.media.tv.action.INITIALIZE_PROGRAMS -n com.projects.test.scheduler/com.projects.test.scheduler.MyIntentReceiver
我明白了
然而,在Android29和30上,我只看到一条调试语句
Job scheduled with 1
为了进一步测试,如果我遵循以下步骤
Job scheduled with 1
onStartJob Called.
你知道为什么它在29号和30号会这样吗
Job scheduled with 1
onStartJob Called.