Not getting FCM notification when app is completely killed - android

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.

Related

Formatting background notifications with notifee

Is it possible to format the notification received when app is in background or in quit state?
Firebase messaging displays the notification as it is i.e. as a json string, and does not hit any of the background handlers, it gets directly displayed in system tray.
So basically we want to receive a notification payload body field as notification json format it to string and display with help of notifee.
you can formate the received notification.
for that you need to send only data in payload and set "content_available" : true,
"priority": "high" just like the below payload
{
"to":"Device_token",
"data": {
"title": "JSON.stringify(owner)",
"body": "JSON.stringify(user)",
"picture": "JSON.stringify(picture)"
},
"content_available" : true,
"priority": "high"
}
when receive on device parse it according to your need

Ionic / Capacitor - PushNotiifcations - Android - “notification” + “data” message

I am using PushNotifications Capacitor plugin and FCM to send the notifications, everything works fine until I want to send a Push Notification with both notification and data fields on Android.
What I want to do is to send a custom data with the notification and consume the notification on app resume. I am using PushNotifications.getDeliveredNotifications() method to get the notifications on resume, on iOS I get all the notifications with proper data, but on Android data property is replaced with the object below:
{
body: "My Body",
data: {
android.appInfo: "ApplicationInfo{809371c app}",
android.bigText: "My Body",
android.progress: 0,
android.progressIndeterminate: false,
android.progressMax: 0,
android.reduced.images: true,
android.showChronometer: false,
android.showWhen: true,
android.template: "android.app.Notification$BigTextStyle",
android.text: "My Body",
android.title: "My Title",
gameDndOn: false,
specialType: "",
topFullscreen: false,
groupSummary: false,
id: 0,
title: "My Title"
}
}
I see in the FCM docs for Android apps that if both notification and data fields are present and the app is in the background the notification lands in the system tray and data in extras of the intent.
I am getting proper data when I tap on the notification, but in my case I want to get that on resume, without tapping on the notification.
Is there any way to get to that data in that case?
You have to create the message in this format
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
},
"data" : {
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
}
}
}
Note : notification structure is critical for receiving a notification. You need to have title and body. This gets displayed in the notification drawer.
data can be customized as per your requirement. This will have the data that you need inside your app.
Suggestion, keep your payload small. Send data which is absolutely necessary and also safe to send over FCM.
Look at this part of the official documentation
For handling push notifications in capacitor, you should use the listeners. Here is the official docs way of doing it.

FirebasePushNotificationPlugin(xamarin) - events not fire when app in background(android)

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

Open a web browser from push notification without launching the application?

My application is running in the background and I send a push notification through postman using the payload below.
Now when I send this, I get the notification and when I tap it, it launches my application's Main Activity. But I want to launch the web browser which opens the link that I send in the notification body. How to do this?? Can somebody please help.
{
"to" : "MY_TOKEN",
"collapse_key" : "type_a",
"notification" : {
"body" : "https://developer.android.com/training/notify-user/build-notification#click",
"title": "Title of Your Notification in Title",
"key_1" : "Value for key_1",
"key_2" : "Value for key_2",
"click_action" : "OPEN_WEB"
}
}

Handle FCM notification In Android Oreo when the App is closed or pause State

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",
}
}

Categories

Resources