push-plugin icon indicating copy to clipboard operation
push-plugin copied to clipboard

Aggregate multiple Android Notifications

Open svzi opened this issue 8 years ago • 9 comments

Hi there!

I’m looking for a way to aggregate my Android Notifications using this push-plugin, because I want to avoid showing 10 times the same message to the user in the notifications bar…

It should be possible to update existing notifications: https://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating

I've already talked with @Pip3r4o about that on Slack, here is what he answered to my initial request:

pete.k [10:19 AM] In the Background Notification demo I did I believe I just pass a certain parameter to the notification service, and no matter how many times the notification is fired, it shows just 1 icon on the notification bar [10:19]
let me check it out [10:22]
https://github.com/NativeScript/sample-android-background-services/blob/master/app/notifications/NotificationIntentService.js#L39 You send a specific flag to the Android Intent. I'd post this as an issue in the respective repo so that it gets looked at

Any way you can add that new feature? I guess it could become handy to a lot of projects. 👍

Best, Sven

svzi avatar Feb 09 '17 13:02 svzi

@svzi Sven, thanks for the suggestion.

There is a similar functionality already implemented in the plugin.

Utilizing the data.notId key in the payload will allow for setting this with server control. For example - sending the same notId with the payload will update the existing notification in the tray with the same notId.

According to your words, this is the functionality you are looking after. Let me know if this is the case.

AntonDobrev avatar Feb 10 '17 12:02 AntonDobrev

@AntonDobrev Anton, thanks for the answer.

I just tried it and sent some pushes with same data.notId, but they all show up in the notification tray of my device. So I guess I'm doing something wrong. Could you please offer any additional documentation or some code sample?

Best, Sven

svzi avatar Feb 13 '17 06:02 svzi

@svzi Sven, here is an example:

Sending the following payload (using the same notId for the pushes you want to replace). For example, these title and message will replace the notification currently in the tray and with the same notId value.

Let me know if this works for you.

{
    "data":{
        "title":"some title 4",
        "message":"some message 4",
        "notId":123
    }
}

AntonDobrev avatar Feb 14 '17 13:02 AntonDobrev

@AntonDobrev Anton, thanks for the example, but sadly that doesn't work. 😞 The notId doesn't change anything.

I've also tried to add it to the notificationproperty instead of data, but that doesn't help either.

This is my complete test push:

{
    to: device_token, // required fill with device token
    collapse_key: 'test_key',
    data: {
        notId: 1,
        your_custom_data_key: 'your_custom_data_value2'
    },
    notification: {
        title: 'Test',
        body: 'test body data.',
        icon: 'notification',
    }
}

For testing purposes I just modify notification.titleand notification.bodyand push again. The old notification in my tray doesn't get replaced, instead the new push message will be added as well.

svzi avatar Feb 15 '17 09:02 svzi

Any update?

svzi avatar Feb 27 '17 14:02 svzi

I haven't tried it myself but, isn't there a "collapse_key" option you set in the payload for this?

See: http://docs.telerik.com/platform/backend-services/javascript/push-notifications/send-and-target/push-set-options.html#android-specific-fields

I DO use Telerik Backend Service but right now I am not using this option.

Daxito avatar Feb 27 '17 15:02 Daxito

It applies when the device is off though, don't know.

Daxito avatar Feb 27 '17 15:02 Daxito

Thanks @Daxito, but you're right. It only applies when the device is offline and the message has not been sent to the device. As you may notice I already use that key (https://github.com/NativeScript/push-plugin/issues/93#issuecomment-279957444).

svzi avatar Feb 27 '17 15:02 svzi

@AntonDobrev Any update on this issue? This is really important to our app!

svzi avatar May 02 '17 11:05 svzi