【发布时间】:2019-11-24 21:32:33
【问题描述】:
我想运行 JobIntentService,但出现此错误!
java.lang.IllegalArgumentException: Scheduled service ComponentInfo{MyIntentService}
does not require android.permission.BIND_JOB_SERVICE permission
谁能帮帮我?
我试过这个JobService does not require android.permission.BIND_JOB_SERVICE permission
但没用。
class MyIntentService : JobIntentService() {
@RequiresApi(Build.VERSION_CODES.O)
override fun onHandleWork(intent: Intent) {
val CHANNEL_ID = "my_channel_01"
val channel = NotificationChannel(
CHANNEL_ID,
"Channel human readable title",
NotificationManager.IMPORTANCE_DEFAULT
)
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).createNotificationChannel(
channel
)
val notification = Builder(this, CHANNEL_ID)
.setContentTitle("adf")
.setSmallIcon(R.drawable.ic_baseline_settings_input_component_24)
.setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
.setSmallIcon(R.drawable.ic_baseline_settings_input_component_24,2)
.setContentText("ewr").build()
startForeground(1, notification)
try {
for (x in 1..10){
Thread.sleep(1000)
Log.d("Nurs", "sleep $x")
}
} catch (e: InterruptedException) {
// Restore interrupt status.
Thread.currentThread().interrupt()
}
}
internal fun enqueueWork(context: Context?, work: Intent?) {
enqueueWork(context!!, MyIntentService::class.java, RSS_JOB_ID, work!!)
}
}
在我调用的 MainActivity 中:
val mIntent = Intent(this, MyIntentService::class.java);
mIntent.putExtra("maxCountValue", 1000)
enqueueWork(this, MyIntentService::class.java,
Companion.RSS_JOB_ID, mIntent)
【问题讨论】:
-
我也面临同样的问题..有什么帮助吗?我在我的情况下使用 JobIntentService 类......而如果我尝试使用 JobSchecular 它正在工作
-
不知道,试试看@CommosWare推荐的样例工程
-
我已经经历过了,但在那个例子中,正在使用 JobService,我正在使用 JobIntentService