【问题标题】:java.lang.IllegalArgumentException: Scheduled service android.permission.BIND_JOB_SERVICE permissionjava.lang.IllegalArgumentException: 计划服务 android.permission.BIND_JOB_SERVICE 权限
【发布时间】: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

标签: android android-service


【解决方案1】:

android:permission="android.permission.BIND_JOB_SERVICE" 添加到您的<service> 元素中,作为您的JobService

<service
  android:name=".WorkService"
  android:permission="android.permission.BIND_JOB_SERVICE" />

(来自this sample project

【讨论】:

  • 我做了,但没有帮助
  • @Nurseyit:您可以下载示例项目并进行试验。或者,您可以使用 minimal reproducible example 更新您的问题,包括您当前拥有的任何错误消息(如果您添加了该权限,它将不再是您在问题中引用的错误消息)。
猜你喜欢
  • 1970-01-01
  • 2011-04-15
  • 2020-03-22
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 2016-12-08
  • 2020-04-27
相关资源
最近更新 更多