Home Ask Login Register

Developers Planet

Your answer is one click away!

FVod February 2016

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?

Thanks in advance


Ravi Rupareliya February 2016

put some flag variable on your notification intent.


Now check it in your Activity, whether Bundle is having "notification" key or not

    //write your code for analytics

abielita February 2016

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.

Post Status

Asked in February 2016
Viewed 1,702 times
Voted 4
Answered 2 times


Leave an answer

Quote of the day: live life