Notifications sample only showing the last received on Android - android

I'm running the Worklight's Notifications sample. I invoke the adapter to send a notification to the application, and it shows the notification into the top bar perfectly.
But when I send another notification, it don't stack with the previous one, it overwrites with the new one.
And I don't want that it being overwriten. How can I solve this?

This is a limitation that is currently imposed (by default) by Worklight.
In essence, in Worklight there is internally a GCMIntentService class that listens for received notifications and if received, creates and sends to the OS an object with a static ID. This is repeated for every incoming notification, replacing the previously received notification.
What you can do is:
Submit a feature request to be evaluated by Worklight's product designers: http://www.ibm.com/developerworks/rfe/
In your project, there is an empty class in android\native\src\com\app-name\GCMIntentService.java. What you could try to do, is basically implement your own "push mechanism" based on Google's documentation to have all notifications display rather than just the last received notification by not using a static id like how it is currently implemented in Worklight.

You need to set a diferent notification id in the client. In the notification manager create a notification id using the timestamp for exemple.

Related

Choose to show or ignore push notifications client side?

We want to send push notifications in Android and iOS to a group of users that match a certain condition. We can check if an user match this condition calling an API.
Our problem is that the users information changes very quickly and we don't have any way to keep track of this in our push notifications engine (OneSignal).
The only alternative we can think is to send the push notification to all users and client side call the API to get the latest user information. Depending on this we could choose to show the notification or ignore it.
Is this possible on Android and iOS?
It is 100% possible for sure. in the receiver class you call an intentservice, which can hit an api and get the latest information, based on the information you create notification using notification builder, and avoid if you dont want.
Yes, with the help of NotificationExtenderService this is possible.
Receive a notification in the background. Notification data is wrapped up in OSNotificationReceivedResult object. Now, read the notification id/title which should be unique for every notification.
Send this unique notification title/id along with user id to an API, which will return whether to show the notification to the user or not. If true then read notification title and message/description from OSNotificationReceivedResult and make a notification via NotificationCompat otherwise just ignore it.
Reference

Handling fcm notification when app not launched

I am using fcm push notification for my android app. I was able to display push notification on system tray when app is not launched. When I tap on the notification it opens the app launcher by default and I start an activity A from there. But the issue is, if I put the app to background and click on the app icon it again opens the app launcher rather than opening existing Activity A.
If the app process is killed, start the launcher activity. If the app is in the background, you can pass an intent to the notification which starts a DummyActivity that has no code on it, and immediatelly calls finish() on its onCreate() method. This will bring your app to the foreground.
Several things are not clear in your question. For example: How you send messages (from developer console or through rest api post requests to firebase backend)? What is your desired behaviour for app when push messages come? I will try to give you general answer that probably helps you to address issue and understand how to implement desired behaviour.
In any case, there are two types of Firebase push messages:
data messages
notification messages
more details about it check on Notification & data messages page
If you want to send additional details to activity that you are starting (something similar to bundle extras), you should use data messages and handle those in your service that extends FirebaseMessagingService by overriding onMessageReceived(RemoteMessage remoteMessage) method. This method is preferable for me because it is much more flexible. You can define all the details about showing notification based on received firebase message, including if notifications are bundled, what happens in details when user click notification and almost everything related to it.
If you don't need to start certain activity with some parameters, than you can use push messages and just define click_action. This method allows you to add define title, text and sound of notification (beside some other details) but it is not as flexible as if you send data messages
Here you can find detailed overview of possible parameters that you can use for different type of messages
Hope this helps

Stacking push notifications in Delphi to Android application

In my delphi code app, Is possible I change the settings of my pending intent used to handle push notifications when It arrives? I´d like to change your behaviour. Instead I have many push icons notifiactions on status bar when each new push messages arrive, I´d like to have only one with a counter increasing when new push messsages arrive. I´d like something as https://developer.android.com/training/wearables/notifications/stacks.html
Luiz
You can implement the logic you want.
When you receive a push, it carries various data.
If a notification is already displaying such data, you can cancel the existing notification and create a new one.
In any way, the notification manager of android will be able to stack notifications by itself for you.
So i suggest, when you receive data from a push:
Store it to sqlite
Calculate the notification ID you need to display that notification (can be a hashCode of the notification type ?)
Fetch all notif for that type from sqlite
Cancel the notification with this ID (don't worry, cancelling a non existing notification won't make your app crash)
Create a shiny new notification with all the data you fetched, if you have more than one, you might want to display "+X other".
EDIT: With my answer, i assumed you can do as much as thing in "delphi to android" than in native android. Hence, i can't provide code for you, but the idea does not depend of the language you are using.

Handling Parse Push Notifications in Android

I am using Parse API in order to handle push notifications. In our Android application, I want to accomplish two things:
1) If we have received a Push Notification with the application is closed and the user clicks on the notification, I want to be able to understand that the application is being opened via a push notification.
2)If we receive a push notification while the application is open, I want to handle this and do some extra work.
In both cases, I want to be aware that the application has received a push notification in order to execute some special operations.
As far as I understand from Parse API documentations, it offers two methods of handling pushes: Responding with an Activity and Responding with an Intent. I am currently calling
PushService.setDefaultPushCallback(context, MainActivity.class);
in my Application class with needed changes in the AndroidManifest.xml file and already receive push notifications, this corresponds to Responding with an Activity method. But I don't know how to be aware of Push Notifications explicity with this method.
Thanks in advance.
When a push is received ,Check
1:Whether our application is in foreground or background.
If it is foreground, that means app is visible and do your stuff(show alerts or anything you want).
If app is in background,that means it is not visible and if you want to do any thing based on this.
i hope this helps..

Android: Right Handling with multiple Notifications

I receive Push-Notifications from GCM and want them to be shown in the Notification-Bar. So I generation the Notifications in the GCMIntentService-class.
If there is already a notification in the notification-area, this notification have to be appended with the new message (with use of the BigTextStyle). But how do I know if there is a notification from my app in the notification-area?
You cannot get existing notification, but you can update existing notification by setting up Notification ID.
NotificationManager.notify(NotificationId, NotificationObject);
No, you can't find out if there's already a notification posted; this is something you should keep track of in your app.
Fortunately, however, the API for updating an existing notification is identical to the API for creating a new one: notify(). That is, once you get new information, add it to some internal buffer (possibly just a StringBuilder) representing the complete set of received push notifications, then build a new notification with Notification.Builder and call notify() with the same ID and tag you used last time. Any existing notification with that ID and tag will be replaced with the new content.

Categories

Resources