Android - DeleteIntent, how to use? - android

I currently have a notification in my Android application that has a PendingIntent so that when it is clicked an activity is opened.
I currently keep a counter for the notification, similar to the native missed calls notification.
I can reset this counter to 0 when the notification is clicked.
I also want to reset the counter to 0 when the user selects the "Clear all notifications" button. I have done a search and seen the way to do this is to use the DeleteIntent.
But I cant figure out how to use this alongside my PendingIntent, can anyone help me out?

Create a broadcast or service PendingIntent, pointing to a BroadcastReceiver or IntentService that will reset your counter, and associate that PendingIntent with your Notification via deleteIntent.

Related

Android receive notification open and cancel event

I receive data from my webService to generate custom notifications.
I want to track Intent to be aware of open (click) or cancel (swipe) event on a notification , to report server for analytics.
Is there any listener for onIntentStart or onIntentCanceled ?
Maybe a listener for notifications by notificationId ?
Edit :
i want to do this without changing user's contentIntent or DeleteIntent or asking user to add lines of code to NotificationHandlerActivity !
You can set contentIntent and deleteIntent using setContentIntent/setDeleteIntent. To find more please visit: Building a Notification.
In addition you can subclass NotificationListenerService which is a service that receives calls from the system when new notifications are posted or removed, or their ranking changed.
Here you can find example how to use it.

Allow user the choice to stop receiving Android notification

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.

Android: Is there a method for after-notification-is-sent?

Trying to implement a snooze functionality on notification. (Correct me if I'm wrong) So I think one of the ways is to modify the alarm manager when the notification is triggered. So anyone knows if there is a method that's called when the notification is called? Thanks in advance.
So anyone knows if there is a method that's called when the notification is called?
I have no idea what you consider "the notification is called" to be.
You provide a PendingIntent to the Notification that will be invoked when the user taps on the Notification in the notification drawer. Usually, that PendingIntent will point to your code: activity, service, or BroadcastReceiver.
For Android 4.1 and higher, you can also have a "big" Notification style that has its own buttons, and you can tie a PendingIntent to each button.
Hence, on Android 4.1 and higher, I would expect "snooze" to be one of these action buttons, and you could use a broadcast PendingIntent to get control and make your changes to your alarm schedule. On Android 4.0 and earlier, "snooze" would be part of the activity that would come up when the user taps on the Notification, and you can adjust your alarm schedule at that point.

Is it possible to listen for when a user cancels a Notification in Android?

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)

Auto Notification for Android

I'm new with Android programming. I'm just wondering whether its possible to set up auto notification. For example, every morning at 8am, the app will send a notification to user about something. Is this possible? Which area/class of Android programming should I look at? Thanks!
You should have a look at the Alarm Manager. You will need to use either of the 'set' methods, and give it a PendingIntent that will perform a broadcast or start an intent service that wakes up just to show the notification. For the broadcast, you will need to have a receiver in your app, that makes a Notification and shows it.

Categories

Resources