If the notification is clicked the application will be opened only if it is was not on the background and if the app is on the background it will not be brought to foreground. Android platform.
So I spent a lot of time finding the bug changing parameters and it turned out that<preference name="AndroidLaunchMode" value="singleInstance"/> parameter at config.xml was causing the problem. We used this parameter because deep links were creating new instances of the app. But for now we will ignore that problem.
Had the same issue but from other reason. The app was not opened when the notification was clicked.
The problem was that I changed the plugin from cordova-plugin-fcm to cordova-plugin-firebase
And the server that send the notification set the click_action to FCM_PLUGIN_ACTIVITY
So I changed (php):
$n = new Notification($title, $body);
return $n->setClickAction("FCM_PLUGIN_ACTIVITY")->setIcon('fcm_push_icon')->setSound('default');
To:
return $n->setIcon('fcm_push_icon')->setSound('default');
add this line in confix.xml
<preference name="AndroidLaunchMode" value="singleTop" />
and build app, works fine for me...
<preference name="AndroidLaunchMode" value="singleTop" />
When you add this line in config.xml even then two cases can happen or these cases might also be happening without adding this line
you won't be able to receive notification when app is in background or killed
if you received background notification even then when you click on
it. It won't open the respective application
So to solve first point, you should send the notification key whose value is object in object of fcm from backend service
So to solve second point, "click_action" key should not be passed in notification object
So your overall FCM object which is passed in fcm api should look like
{
"notification": {
"title": "Test Title",
"body": "message",
"sound": "default",
"icon": "fcm_push_icon",
"image": ""
},
"data": {
"action": "TEST"
},
"to":"caRvu_MeTN6HbMZKHfOO7y:APA91bEOEOAhpZNrDcDWew0uXM1HfKavyXbf3q4U090AHW5FmD7kDDxs4BRquaM*******************************************",
"priority": "high"
}
NOTE: This thing is only tested for Capacitor Fcm Plugin
Hope this will help you or somebody else :-)
Thanks!
Related
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
I'm using com.google.firebase:firebase-messaging:20.0.0 on Android. When I try sending a notification like the one below it always shows the normal title and body instead of title_loc_key and body_loc_key when they are presented in the app! The fun thing is that it's not the case in iOS. In iOS it will always try to first show the localized resources and if it couldn't find them, it will default to normal ones.
{
"to" : "f6_numko7IQ:APA91bFrTN0fmThFDeAFy2...",
"collapse_key" : "type_a",
"notification" : {
"title_loc_key": "resource_name_1",
"body_loc_key": "resource_name_2",
"title": "Default Title",
"body": "Default Body!"
}
}
Is this a known issue? Is there a get around for it?
The solution is to remove the "title" and "body" entries. I know it should work like on iOS but currently it's not.
{
"to" : "f6_numko7IQ:APA91bFrTN0fmThFDeAFy2...",
"collapse_key" : "type_a",
"notification" : {
"title_loc_key": "resource_name_1",
"body_loc_key": "resource_name_2",
}
}
For Android: Using the "v1" api from firebase remove "title" and "body" from root "notification: {....}" and add into the "android": {
"notification": {
"title_loc_key": "push_notification_title",
"body_loc_key": "push_notification_body"
}
},", should work.
But you need to keep in mind the following:
The push notification will be displayed by default by firebase SDK based on the com.google.firebase.MESSAGING_EVENT, when the app is in the background --> opened (the process is in the background) and Notification permission is allowed. Also, you need to be sure that your app has already a channel created with the default_channel_id you defined in the manifest file. For this case, you will not be notified of the onMessageReceived callback provided by "FirebaseMessagingService".
When the app is in the foreground you will not receive any firebase notification, visible on the screen. Based on the Channel you have created at point 1) you need to trigger the notification display if required, by creating a NotificationBuilder .... and displaying it. This catch must happen inside the: onMessageReceived callback provided by "FirebaseMessagingService"
When the app is closed and notification is allowed the push notification will be displayed by default by firebase SDK based on the com.google.firebase.MESSAGING_EVENT. However, if the notification received by the device contains some data: {} payload that can be handled into the onCreate lifecycle method from activity by accessing the this.intent.extras. You will not be notified of the onMessageReceived callback provided by "FirebaseMessagingService".
If notification is disabled you will not get any push notification displayed visually but when the app is in the foreground you will be notified into the onMessageReceived callback provided by "FirebaseMessagingService". When the app is closed or in the background, you will get nothing.
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.
We are using firebase push notification in Android and in iOS. The push is sent using FCM REST API call. Push type is notification with extra data node.
Here is a sample payload:
{
"notification" : {
"title": "title text",
"body": "message body text",
"sound": "default"
},
"data": {
"messageType": "xxx"
},
"to": "yyy",
"priority": "high",
"time_to_live": 0
}
This type of push notification does not show a heads up display when the app is in background and phone is on. -- Notification just are added to notifications bar but are not sneak peaked to user at the top of the screen. -- no matter if the current app is full screen app or not.
One solution that I have tried and is working is to shift to pure data message where we will not send any notification node, but just the data node and write the code to show notification ourselves and set notification priority to Max (ie .setPriority(Notification.PRIORITY_MAX)) on notification builder object.
But this seems to have issues on iOS where data only pushes are not received/shown to user if the app killed by user.
So is there any workaround to this? any solution that works on Android, but also does not break iOS.
You should set the NotificationPriority to PRIORITY_HIGH or PRIORITY_MAX for Android to show the notification. See Android Notification and Notification Priority for more details.
You should set these values using the constants, not using the strings. E.g.
{
token,
android: {
notification:
{
title,
body,
// See https://developer.android.com/reference/android/app/Notification#PRIORITY_MAX.
// This is deprecated in Android API level 26, but works for older versions.
notification_priority: 2,
// Always allow Android users to see the message in its entirety.
// See https://developer.android.com/reference/android/app/Notification#VISIBILITY_PUBLIC
visibility: 1
}
}
}
I am using the Native Push Plugin for an Android application I'm developing. I have configured an icon and an icon color for my notifications like this:
let push = Push.init({
android: {
icon: "ic_notif",
iconColor: "#f94915",
forceShow: true, ...
If I send a notification through the Firebase console (Target = User Segment -> App -> My App) and I'm in the foreground (the application is visible), my notification icon is displayed correctly in the notification area (the icon color as well in the notification drawer). However, if my application is in the background (or not started at all) and I send a message, I get a white square instead (and the icon color in the notification drawer is the default gray).
By looking through the source code, in GCMIntentService.java, I discovered that the method onMessageReceived handles the incoming message. When I'm in the foreground, the following condition is fired:
else if (forceShow && PushPlugin.isInForeground()) {
Log.d(LOG_TAG, "foreground force");
extras.putBoolean(FOREGROUND, true);
extras.putBoolean(COLDSTART, false);
showNotificationIfPossible(applicationContext, extras);
}
The method showNotificationIfPossible is responsible of creating the notification (icon, icon color, vibration, sound, etc.). The problem here is that it seems that the code is not being executed while the application is in the background (I'm getting the message nonetheless), specifically the following code, and that's what I think it's the problem here:
// if we are not in the foreground always send notification if the data has at least a message or title
else {
Log.d(LOG_TAG, "background"); //this is not being logged at all
...
Does anyone have any idea what's going on here?. I guess I need to check the source code more thoroughly to figure it out.
The syntax of manifiest.json file has updated and there are some new things came around, pls check in below example are those same in your case ?
{
"name": "Ionic",
"short_name": "Ionic",
"start_url": "index.html",
"display": "standalone",
"icons": [{
"src": "assets/imgs/logo.png",
"sizes": "512x512",
"type": "image/png"
}],
"background_color": "#4e8ef7",
"theme_color": "#4e8ef7"
}
from this file you can do whatever ui changes you need.