java.lang.IllegalArgumentException: 定时服务 android.permission.BIND_JOB_SERVICE 权限
java.lang.IllegalArgumentException: Scheduled service android.permission.BIND_JOB_SERVICE permission
我想 运行 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)
将 android:permission="android.permission.BIND_JOB_SERVICE"
添加到 <service>
元素中 JobService
:
<service
android:name=".WorkService"
android:permission="android.permission.BIND_JOB_SERVICE" />
(来自 this sample project)
我想 运行 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)
将 android:permission="android.permission.BIND_JOB_SERVICE"
添加到 <service>
元素中 JobService
:
<service
android:name=".WorkService"
android:permission="android.permission.BIND_JOB_SERVICE" />
(来自 this sample project)