Detect when Notification is clicked to send analytic's event
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?
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.
Asked in February 2016Viewed 1,702 timesVoted 4Answered 2 times