3

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 !

Mojtaba Yeganeh
  • 2,788
  • 1
  • 30
  • 49

1 Answers1

4

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.

Ziem
  • 6,579
  • 8
  • 53
  • 86
  • 1
    thanks ! , i vote this because your answer were helpful but i think there is another way ! , in parse.com push notification , parseAnalytics.trackInBackground(intent) do this ! , can this help you to improve your answer ?! – Mojtaba Yeganeh Apr 27 '15 at 20:52
  • please take a look at this , https://parse.com/docs/push_guide#receiving-tracking/Android – Mojtaba Yeganeh Apr 27 '15 at 20:57
  • I think the magic is to add `action` on intent and receive it with `BroadCastReceiver`s ! – Mojtaba Yeganeh Apr 27 '15 at 21:12
  • @ALU0075 - I have never used parse. In my opinion they are doing `setContentIntent` because then they order you to pass `Intent`: `ParseAnalytics.trackAppOpened(getIntent());`. **From parse website**: To track push opens, you should always pass the Intent to trackAppOpened. Passing null to trackAppOpened will track only a standard app-opened event, not the push-opened event. – Ziem Apr 28 '15 at 06:31
  • @Zeim - but this will overwrite `ContentIntent` and `DeleteIntent` and intent will not do what user wants ! – Mojtaba Yeganeh Apr 28 '15 at 08:27
  • is it possible to set two `ContentIntent` Or `DeleteIntent` ?! – Mojtaba Yeganeh Apr 28 '15 at 08:34
  • No, it's not possible to set two `Intent`s. However you can put custom values to `Intent` using `intent.put*(...)`. – Ziem Apr 28 '15 at 08:42
  • if i put some extra on intent , i need to handle it in Activity , maybe tell user "extends your activities from `PushHandlerActivity`" but this is not what parse is doing ! , maybe adding an Action on intent and receive that with BroadCastReceivers is the right way ! , i mean when intent called , just call my `OnOpenBroadCastReceiver` , any idea ?! – Mojtaba Yeganeh Apr 28 '15 at 08:51
  • I didn't tell you to extend any `Activity`, just put extras to intent and use them in your `Activity`. – Ziem Apr 28 '15 at 09:03