'How to prevent head-up notification from dismissing when it is clicked in Android 6?

As i wrote in the title of this question, how can i prevent head-up notification from dismissing when it's clicked? this only happens on Android 6 Mashmellow(API 23).

If i click the head-up notification, it's cleared and also i can't see it in the status bar where time and notification are. but if i swipe it out, the head-up notification is going to dismiss and also i can see it in the status bar. So, when swiping, it's okay.

please check my code below.

val notification = NotificationCompat.Builder(this, CHANNEL_ID).apply {
            setContentTitle("MyApp")
            setContentText("Download....")
            setSmallIcon(R.drawable.push)
            setLargeIcon(BitmapFactory.decodeResource(applicationContext.resources, R.mipmap.icon))
            priority = NotificationCompat.PRIORITY_HIGH
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
                setSound(Uri.parse("android.resource://" + applicationContext.packageName + "/" + R.raw.push_alert))
            }
            setContentIntent(pendingIntent)
        }.build()

Thus, what i want to know is only about preventing the head-up notification from clearing when it's clicked.

how can i fix it??



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source