Java 自定义通知按钮:无法启动服务意图错误
我正在制作一个自定义媒体播放器通知。当我想在按钮上附加一个动作时,我遇到了下面的错误 错误:无法启动服务意图{act=left flg=0x10000000 cmp=com//package\U name//.model.media\U player$NotificationIntentService bnds=[630195][780345]}U=0:未找到Java 自定义通知按钮:无法启动服务意图错误,java,android,kotlin,notifications,android-mediaplayer,Java,Android,Kotlin,Notifications,Android Mediaplayer,我正在制作一个自定义媒体播放器通知。当我想在按钮上附加一个动作时,我遇到了下面的错误 错误:无法启动服务意图{act=left flg=0x10000000 cmp=com//package\U name//.model.media\U player$NotificationIntentService bnds=[630195][780345]}U=0:未找到 class media_player(val applicationContext: Context?, val playPauseBu
class media_player(val applicationContext: Context?, val playPauseButton: ImageButton, var selectedAudio: AudioModel) {
private val channelId = "com.project_education.relaxandfocusfree.model"
class NotificationIntentService
: IntentService("notificationIntentService") {
override fun onHandleIntent(@Nullable intent: Intent?) {
when (intent!!.action) {
"left" -> {
val leftHandler = Handler(Looper.getMainLooper())
leftHandler.post(Runnable { Toast.makeText(baseContext, "You clicked the left button", Toast.LENGTH_LONG).show() })
}
"right" -> {
val rightHandler = Handler(Looper.getMainLooper())
rightHandler.post(Runnable { Toast.makeText(baseContext, "You clicked the right button", Toast.LENGTH_LONG).show() })
}
}
}
}
@RequiresApi(Build.VERSION_CODES.O)
fun mediaNotification(notificationManager: NotificationManager, context: AudioPlayerActivity){
val notificationLayout = RemoteViews(context.packageName, R.layout.media_notification)
val customNotification = NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.play_button)
.setCustomContentView(notificationLayout)
.setTicker("Ticker Text")
.setStyle (NotificationCompat.DecoratedCustomViewStyle());
notificationLayout.setImageViewResource(R.id.imageButton3, R.drawable.previous_button)
notificationLayout.setImageViewResource(R.id.imageButton2, R.drawable.next_button)
notificationLayout.setImageViewResource(R.id.imageButton, R.drawable.play_button)
notificationLayout.setTextViewText(R.id.textView2, selectedAudio.audioName)
notificationLayout.setTextViewText(R.id.textView, selectedAudio.audioArtist)
val leftIntent = Intent(context, NotificationIntentService::class.java)
leftIntent.action = "left"
notificationLayout.setOnClickPendingIntent(R.id.imageButton, PendingIntent.getService(context, 0, leftIntent, PendingIntent.FLAG_UPDATE_CURRENT));
notificationManager.notify(1, customNotification.build())
}
很明显,你的服务没有登记在舱单上。谢谢你,它没有工作。