0

I would like to try and make a Notification that does not respond to a click. Is this possible? i.e. when it is visible in the Notification area, and the user touches it, I want "nothing" to happen.

This is different to a normal Notification - when it is visible, and the user touches it, the Notification Area hides, and the Intent is launched. I do not want the Notification Area to hide when it is touched.


I can make one that doesn't launch an activity:

But it still responds to a click, by hiding the notification bar again (i.e. standard expected behaviour).


This question is a duplicate of How to disable a click event of notification in android development but that question does not have an answer. (if there is a better way to ~bump~ that question up again, I will do that & delete this question)


Note: I know this is not "the Android way", but it is still something I would like to try.

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255

3 Answers3

4

Use Intent intent = new Intent() and insert this into the PendingIntent.

Jeff Bootsholz
  • 2,971
  • 15
  • 70
  • 141
4

I do not want the Notification Area to hide when it is touched.

That would require firmware modifications. You are not in control over the notification area; the OS is.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

Have you ever tried

new NotificationCompat.Builder(this, CHANNEL_ID)
    .setSmallIcon(R.drawable.notification_icon)
    .setContentTitle("My notification")
    .setContentText("Hello World!")
    .setPriority(NotificationCompat.PRIORITY_DEFAULT)
    // Set the intent null or empty and autoCancel false
    .setContentIntent(null)
    .setAutoCancel(false);

For more info about setAutoCancel() check Android Document here.