1

I made an app that works in the place of the stock messages app. It's basically a popup that displays the text message when it comes in.

When a text message comes in, the phone obviously puts a notification in the notification tray. How do I clear this notification once the user has viewed my popup? When he views my popup, the message is marked as "Read" in the inbox, but the notification isn't cleared. How do I do this? Thanks!

A--C
  • 36,351
  • 10
  • 106
  • 92
NewGradDev
  • 1,004
  • 6
  • 16
  • 35

2 Answers2

1

In the notification builder use the setAutoCancel() method:

NotificationCompat.Builder builder = new NotificationCompat.Builder(
                context);
builder.setAutoCancel(true);
bkurzius
  • 4,020
  • 2
  • 34
  • 34
  • Thanks, but I'm not trying to clear my own notification. When a text message comes in, the Android Messages app creates a status notification... that's the notif that I'm trying to clear. Is there any way to do this? – NewGradDev Feb 18 '13 at 01:25
  • From this thread, it looks like you can't remove a notification you didn't create: http://stackoverflow.com/questions/2665634/how-to-clear-a-notification-in-android – bkurzius Feb 19 '13 at 01:45
1

You can include NotificationListenerService in your project which allows you to listen to all the Notifications that are posted on the phone.

After that you can use cancelNotification() method to clear the notifications you want to dismiss.

Note that user needs to explicitly grant your application Notification Access Permission in order for your application to access the notifications.

Mike M.
  • 38,532
  • 8
  • 99
  • 95
harsh201
  • 121
  • 5