The Android Wear OS has recently been updated to 5.0, which includes the feature to "recover" the most recently dismissed notification.
As a consequence, a notification's delete intent is only triggered after the user can no longer recover the intent (after another notification is dismissed, or the user swipes down and lets the 'dismiss' timeout expire).
I am attempting to display a notification, which gets updated fairly regularly until the user dismisses it. For this, I need to know immediately when the user has dismissed the notification (before the "recover" option has expired), so that I can stop updating the notification. If I attempt to update the notification once it has been dismissed, it will launch a new notification. In effect, the notification can't be dismissed as it will be recreated immediately.
So my question is: Has anyone discovered a way to detect immediately when the user dismisses a notification on an Android Wear device, before the option to recover the notification expires? I suspect if such a method exists, it should also be possible to detect when the user recovers the notification.
How about this?
Setting this flag will make it so the notification is automatically canceled when the user clicks it in the panel. The PendingIntent set with setDeleteIntent(PendingIntent) will be broadcast when the notification is canceled.
public NotificationCompat.Builder setAutoCancel (boolean autoCancel)
As I see it, it dismisses the notification immediately and it sends the setDeleteIntent() at the same time
Related
I wrote an app for Android L only that listens to USB connection using Broadcast Receiver.
This receiver fires a notification every time onReceive is called.
I think user would find it annoying so I would like to give user a chance of disabling it. I know in Android L user can disable this in Settings -> Sound & notification -> App notification but I would like to add this function on my notification itself.
So my question is, is it possible to add a checkbox on the notification and when checked, disables this notification with the App notification settings gets updated?
thanks
From android 4.1 and up you can use .addAction(R.drawable.icon, "Name", pendingIntent) on your Notification.Builder to add a button on the notification. This will launch the pending intent that you specified. There you can save a boolean value on sharedPreferences to enable or not the notifications which you will check before starting the notifications.
If you dont have any kind of ui and only need to call a service from the button, check here on how to achieve this.
I have a background service setting up a notification in Android's status bar. The background service is doing some work, but needs to stop when the user clicks on or cancels the notification.
I am able to stop the service, if the user clicks on the notification by passing an intent to the notification when creating it.
Is it possible to react if the user cancels the notification? Or if all notifications are canceled? If so, how?
NB: I define cancel as removing the notification by swiping to the right on it, or clicking on the x at the top right to remove all the notifications.
Check out the deleteIntent of the Notification:
The intent to execute when the status entry is deleted by the user with the "Clear All Notifications" button.
I'm interested to know when a user cancels a Notification from by application - is this possible? I'd like to listen for the event and then stop a service that runs in the background.
There is not any way to see if notification was deleted by user. You can make notification "persistent" - it can't be cleared - and start some action when user clicks on it.
You know that we append a PendingIntent in notification, so by using that intent we can launch an activity which may close the service and then call finish() on itself to go away. The entire process might be fast enough that a user may not notice any hiccup
You can set a PendingIntent sent when the notification is cleared explicitly by the user.
Please, take a look over here: Notification.Builder setDeleteIntent (PendingIntent intent)
In my app, when a user executes and event, I add a notification to the notification's bar. Tapping that notification works both if the app is in the foreground or if it is backgrounded.
I would like the notification to persist even if the app is terminated (due to memory, etc.). And have the notification tap relaunch the app.
Is that, at all, possible?
I've searched all over and can't find an answer.
I have set my notification flags to Notification.FLAG_NO_CLEAR so the user can't clear it, but upon app termination, the notification gets removed.
You probably want the notification to be managed by a service. Services can be configured to restart automatically on termination.
My app pops up a message count notification and sets it as "ongoing". There is a timer that re-sends the notification every 5 minutes, and the notification has the flag Notification.FLAG_ONGOING_EVENT , so that it can only get cleared by my app. And my app is set up to only use sound and vibrate if the count changes.
So, the idea is that if my app changes the count, it sends out an updated notification, which replaces the old one, and plays a sound and vibrates. But if the 5 minute timer tries to update the notification, but the count didn't change, the notification is still sent. but without sound or vibrate. This is done in case the notification somehow got cleared, I want it to pop back up, but if it's still there, I don't want the user to be re-notified.
I also save the message count so that it's remembered if the app is closed and then re-opened. The problem is that when that happens (if it's force-closed, for example), the old notification stays in the bar, but the newly opened app has no idea that's the case. So I'd like to be able to somehow poll the notification service to see if that original notification is still showing, but I can't find any API to do this. Is it possible?
Thanks.
So I'd like to be able to somehow poll the notification service to see if that original notification is still showing, but I can't find any API to do this. Is it possible?
No.
However, you can use deleteIntent to find out if the user cleared the Notification. Either that, or track down the cause of your "somehow got cleared" issue.