Custom Notification Button : Unable to start service Intent Error

0

I am working on a custom media player notification. When I wanna attach an action to button I faced with error below.

ERROR : Unable to start service Intent { act=left flg=0x10000000 cmp=com.//package_name// /.model.media_player$NotificationIntentService bnds=[630,195][780,345] } U=0: not found

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())
}
java
android
kotlin
notifications
android-mediaplayer
asked on Stack Overflow Oct 19, 2020 by Yakup şeker

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0