When sending two notifications the second one always overrides the first one in the notification center.
According to the docs this should happen only when using the tag:
"tag": Indicates whether each notification message results in a new
entry on the notification center. If not set, each request creates a
new notification. If set, and a notification with the same tag is
already being shown, the new notification replaces the existing one.
However this happens to me all the time, regardless whether I set a value for the tag or not.
I even tried setting a random tag & collapse_key (which as far I understand shouldn't be related in this case, but I gave it a try). Still didn't help.
Here's a sample of a notification object I'm sending:
{
"tokens":[
"my-device-token"
],
"profile":"my-profile-tag",
"notification":{
"message":"message",
"android":{
"payload":{
"collapse_key":9918519,
"tag":2825928
}
}
}
}
I resolved this problem.
You need to add "notId" into "data" in "android".
Example:
"notification": {
"title": "testing stack notification ",
"message":"is it working",
"android": {
"data": {
"title": "testing stack notification",
"message": "is it working",
"style": "inbox",
"summaryText": "yes its %n% notifications",
"notId": "123456"
}
}
}
You need to specify a unique notification id (unix timestamp for example) in the object in order not to overwrite the previous one - in your case:
{
"tokens":[
"my-device-token"
],
"profile":"my-profile-tag",
"notification":{
"notId": <some-unique-value-here>,
"message":"message",
"android":{
"payload":{
"collapse_key":9918519,
"tag":2825928
}
}
}
}
Related
I have a custom notification channel that never gets triggered. I read all the documentation for server and client but I'm still missing something.
What I want
I want to send a high-priority push notification via FCM to eventually wake up a foreground service in the app. Therefore I defined a custom notification channel. I want to receive the push, find out that it was sent to the custom channel, and show a notification.
My Problem
I receive all push notifications from firebase as expected but the channelId is always null.
The Setup
We use FCM directly on both sides, the server and the android app.
Our users use Android 8.1 and higher. No legacy push is needed.
The backend sends a JSON that looks like the following:
{
"notification": {
"android_channel_id": "MY_High_Prio_Push_Channel"
},
"data": {
"notificationBody": "BodyText",
"notificationTitle": "Title"
},
"priority": "high"
}
The App has registered the push channel successfully. I can see it in the device settings. The push channel will be re-registered on any app start like this
private fun registerHighPrioPushToRestartTheForegroundService() {
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val channel = NotificationChannel(getString(R.string.push_channel_id_high_prio), getString(R.string.push_channgel_sync_with_high_prio), NotificationManager.IMPORTANCE_HIGH)
channel.setShowBadge(true)
notificationManager.createNotificationChannel(channel)
}
At Runtime
If the android device receives a push from FCM onNewMessageReceived() is called. I then check what channelId it was sent to by calling:
if (remoteMessage.notification?.channelId == getString(R.string.push_channel_id_high_prio)) {
// I would love to do my channel specific stuff here
}
As you can see in the screenshot below the body contains the full JSON. All other values are null.
The problem was on the server side. The whole JSON for the push was put in the body tag of the notification. Now that this is fixed we send a JSON like the following and the parsing in the client works as expected. We removed the notification tag so that onMessageReceived() will be called on every single push.
{
"to": "{devicePushToken}",
"android": {
"priority": "high"
},
"priority": 10,
"data": {
"title": "Some Title",
"body": "Some Message",
"android_channel_id": "yourUniquePushId"
}
}
I use this plugin for my Xamarin Forms app(android).
Any event not fire when app is in background. Events work when the application is in the foreground. But app is background any event not fire, the app is just opening. But I need to pass the message parameters to the application. I'm not sure if this is a bug, maybe this is my mistake. I will be grateful for any help.
I use this api for send message:
https://fcm.googleapis.com/fcm/send
This is my payload:
{
"data": {
"id_serv" : "12",
"id_group" : "1",
"click_action":"Accept"
},
"notification" : {
"body" : "test",
"title" : "test"
},
"priority": "high",
"condition": "'g1' in topics"
}
I also subscribe to all available events - OnNotificationAction, OnNotificationOpened, OnNotificationReceived.
I also try to subscribe at the android level, but this also does not work. Any help?
When the app is in the background firebase use their notification system that way your code not called.
If you want that your code will be called you need to pass the data through the data object only and not use the notification object.
so your notification object need to be like that:
"data": {
"id_serv" : "12",
"id_group" : "1",
"click_action":"Accept",
"body" : "test",
"title" : "test"
},
"priority": "high",
"condition": "'g1' in topics"
}
More info here: FB Receive massages
i don't know anything about xamarin, but in firebase version above 16, you just got push notification data when app is running,
when app is killed: after click on notification, android open your first activity with bundle (extra data), and you must get this data and use them, so debug your app and check your first activity bundle after clicking on notification
Here I facing Notification issue in Android Oreo, That is when the FCM sent push notification to the Android Oreo, it will show the notification when the app is run in the foreground ,that is because of the service is running in the background , it can handle additional parameters and its value , but the problem arise when the app is close or paused state , The OS destroy the Service automatically when the app is closed or paused states , in order the handle notification FCM provides High priority Push notification method ,in which the push notification Json has two parts ,one is "data" , and another one is "notification", The data part can handle by the services when the app is running in foreground , but the Notification part manage by Android OS , There are default keys to handle notification for display notification icons ,title,messaged and Priority , With the use of high priority push notification can wake up the app when we hit on the notification ,and access the information by applying bundle with the starting Activity . but the problem is how to put extra data in In notification , when I trying to add additional data in to the "notification" part into the Json ,The OS not displaying notification . So how can I manage this issue .. ?
{
"to" : "e1w6hEbZn-8:APA91bEUIb2JewYCIiApsMu5JfI5Ak...",
"notification": {
"body": "message",
"title": "Title",
"icon": "appicon"
},
"data" : {
"body": "message",
"title": "Title",
}}
Try to add an extra parameter in notification object from server side manually. It worked for me.
{ "to" : "e1w6hEbZn-8:APA91bEUIb2JewYCIiApsMu5JfI5Ak...",
"notification": {
"body": "message",
"title": "Title",
"icon": "appicon" ,
"extra_param":"value"
},
"data" : {
"body": "message",
"title": "Title",
}
}
I have been trying to send the Push notification using FCM. It works completely when the app is in Foreground or background. But if i kill the app from recent list then i'm not getting any notification.
This is my structure of FCM with data payload
{"registration_ids":["here is my FCM token"],
"data":{
"body" :"Hello All, Hope you had a great time!",
"title":"Title",
"click_action":"ACTIVITY_MESSAGE",
"sound":"default",
"type" : "message",
"message": "message_here",
"time" : "2016-12-14 03:37:pm"
}
}
This is the structure with data and notification
{"registration_ids":["Here is my FCM token"],
"notification":{
"body" : "Hello All, Hope you had a great time!",
"title":"title here",
"click_action":"ACTIVITY_HOME",
"sound":"default"
},
"data":{
"type" : "message",
"message": "message_here",
"time" : "2016-12-14 03:37:pm"
}
}
I have also tried the same with notification tag and data as well but nothing is working in case whent the app is killed. If any one have any idea how can i get the notification in case of my app is killed then do share.
You should try to put "forceStart": "1" inside the data brackets.
In this way you should force the application to start the notification.
I'm developing an application with Kony, and I need to send some notification to user device.
If the device is an iOS one, the notification is handled right (the notification can be dismissed).
But if the device is an Android one, I'm not able to dismiss the notification from the notification center by swiping it and this is really frustrating for the user experience.
This is the JSON I'm sending to GCM:
{
"notification": {
},
"data": {
"notifyData": [
<some app related datas>
],
"title": <notification title>,
"description": <notification body>
},
"registration_ids": [
<device registration id>
]
}
I've tried setting on "notification" block either "ongoing" and "autoCancel" flag, but nothing change.
How can I let the notification be dismissable?
Please go through with the below doc link,
http://docs.kony.com/konylibrary/visualizer/visualizer_user_guide/Default.htm#Custom_GCM.htm#Modifyin
You need to modify the notify_push_msg_clear value in pushconfig.xml file. Change the value to false to dismiss the notification.