6

I've done some searching and have been unable to find anything even closely related.

When a user cancels a notification in Android (by swiping the notification to one side of the screen), does anyone know of clean way to detect this? I think it would be a rather handy feature in an app to be able to cancel a notification and have the app recognize this and mark something as read in the app instead of clicking the notification and opening the app to mark something as read.

Luke
  • 1,069
  • 18
  • 28

3 Answers3

8

Came across this question today. It looks like the second answer has an interesting solution to detect if a notification is still shown or not. This works for pre API 11 devices. Any device running API 11 or newer can use the setDeleteIntent() to fire a PendingIntent when the notification is cleared.

Community
  • 1
  • 1
Luke
  • 1,069
  • 18
  • 28
2

Luke's answer helped me with this. Thanks!

I also found this setDeleteIntent() example which I share for everyone's reference.

how to use delete intent to perform some action on clear notification?

Community
  • 1
  • 1
Anthony De Souza
  • 544
  • 5
  • 10
1

If you mean, how to detect the swipe action for the sliding drawer which is used in the Notification bar, It's not possible dude...

Manjunath
  • 2,063
  • 2
  • 29
  • 60
  • I think you're talking about opening the notification bar, but my question was about canceling a notification. – Luke Apr 18 '12 at 06:09
  • you mean, clearing a notification ? – Manjunath Apr 18 '12 at 06:10
  • yes. clearing, canceling same thing. – Luke Apr 18 '12 at 06:15
  • Try Overriding cancel() of NotificationManager class – Manjunath Apr 18 '12 at 06:20
  • I don't think that would be of much use or work. That might be useful if you wanted to do some additional work when you call .cancel() in your app, but I don't think you would be able to discover when the notification was canceled/cleared by the user by overriding it. – Luke Apr 18 '12 at 06:30
  • Then, I don't know dude. But I had replied you referring this link : https://groups.google.com/forum/?fromgroups#!topic/android-developers/5y9DFmzX79w – Manjunath Apr 18 '12 at 06:34
  • Looks like it isn't possible then... – Luke Apr 18 '12 at 06:40