0

I want to run JobIntentService, but I get this error!

    java.lang.IllegalArgumentException: Scheduled service ComponentInfo{MyIntentService} 
does not require android.permission.BIND_JOB_SERVICE permission

can anybody help me?

I tried this JobService does not require android.permission.BIND_JOB_SERVICE permission

but it doesn't help.

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!!)
}

}

in MainActivity I call :

   val mIntent =  Intent(this, MyIntentService::class.java);
    mIntent.putExtra("maxCountValue", 1000)
    enqueueWork(this, MyIntentService::class.java,
            Companion.RSS_JOB_ID, mIntent)
Nurseyit Tursunkulov
  • 8,012
  • 12
  • 44
  • 78

1 Answers1

0

Add android:permission="android.permission.BIND_JOB_SERVICE" to your <service> element for your JobService:

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

(from this sample project)

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I did but it doesn't help – Nurseyit Tursunkulov Nov 24 '19 at 12:14
  • @Nurseyit: You might download the sample project and experiment with it. Or, you could update your question with a [mcve], including whatever error message you have currently (which, if you added that permission, will no longer be the error message that you cited in your question). – CommonsWare Nov 24 '19 at 12:34
  • But the error says it does not require permission then why we need to mention same permission – androidXP Oct 18 '22 at 13:35
  • @androidXP: The error message is stating that the current code does not meet the requirements. I agree, though, that the error message is written poorly. – CommonsWare Oct 18 '22 at 13:42