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.
Related
Now, my app receive notification from Firebase and I use NotificationListenerService for get event when received and delete/remove notification. it's works fine.
But in onNotificationRemoved I want to know status of notification close by user click open or delete it. What should I do??
Help me please.
This is my code
When posting a notification with help of notificationCompat builder, you can set "DeleteIntent" in it you can set PendingIntent with broadcast receiver to get the broadcast whenever user delete or swipe out your notification.
We have an app with GCM notifications working fine, we set a PendingIntent so the activity that we want is open when the notification is clicked. However, we need to send an event to Google Analytics each time that one notification (and there are different types of notifications) is clicked. How could we achieve this? I don't want to parse the intent in the activity, as I think that this would not be a good solution (we are using TaskStackBuilder so not always the same activity is open for the same notification), is there a receiver we can use to detect when the notification is clicked/open?
Thanks in advance
put some flag variable on your notification intent.
intent.putExtra("notification","clicked");
Now check it in your Activity, whether Bundle is having "notification" key or not
if(getIntent().hasExtra("notification"))
//write your code for analytics
Try using NotificationListenerService. It allows an application to receive information about notifications. You need to declare the service in your manifest file with the BIND_NOTIFICATION_LISTENER_SERVICE permission and include an intent filter with the SERVICE_INTERFACE action to extend this class. See this example.
I also found this stackoverflow question on how to implement NotificationListenerService using TaskStackBuilder. This might help.
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.
My little app sends some notifications. We get a callback via a Pendingintent when the notification is clicked on. However, when a notification is simply removed without being clicked on, I don't get any kind of notification and thus wouldn't know if a notification has been removed by the user.
My ultimate goal is to limit the number of active notifications sent by my app to no more than 3. But I haven't been able to find a way to enumerate or simply get the count of active notifications sent by my app. The number of methods available in NotificationManager is rather limited.
Any help will be appreciated.
You can set a PendingIntent with setDeleteIntent() which will be called when the notification is removed from the notification tray (such as when the user swipes to dismiss it).
Do note that the notification design guidelines state:
If a notification of a certain type is already pending when your app tries to send a new notification of the same type, combine them into a single summary notification for the app. Do not create a new object.
A summary notification builds a summary description and allows the user to understand how many notifications of a particular kind are pending.
I.e., don't do this:
Do this (this example uses an InboxStyle notification as is recommended):
Make sure you are not posting multiple notifications of the same type.
the method "Notification.deleteIntent" you can use to set a PendingIntent which the notification was removed by system will be called .And then you can do something you want .
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.