Android GCM Notification Arriving On Device But Not Displayed - android

I'm firing a message at GCM and it arrives on my device since I see logging on Android Studio Console.
The message as it goes out from my server has the format:
{
"to": "fsfsdfsdfsadf",
"notification": {
"title": "Alert Title",
"body": "Alert body with detailed description.",
"icon": "#drawable/ic_launcher"
},
"data": {
"title": "custom",
"user-id": "123",
"user-age": "44",
"parameters": [{
"parameter": "1"
}]
}
}
I have a very similar thing on iOS where the displaying of the notification is handled by the OS and then when a user taps on the notification a method is called where I do further processing, namely I use the 'data' key.
{
"aps": {
"alert": {
"title": "Alert Title",
"body": "Alert body with detailed description."
},
"content-available": false
},
"data": {
"title": "custom",
"user-id": "123",
"user-age": "44",
"parameters": [{
"parameter": "1"
}]
}
}
My understanding, perhaps incorrectly, is that if I include the 'notification' key in my message then Android will display the notification in the System Tray; just like on iOS the operating system will display the notification if you include the 'alert' key.
Am I correct?

Notification messages are delivered to the notification tray when the app is in the background. For apps in the foreground, messages are handled by these callbacks, onMessageReceived() in case of android
If you are app is in foreground you need to handle the display of notification, OS will only display the notification if app is in background. Refer to the official documentation for more details.

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

Flutter: How to define notification channel in firebase_messaging package?

I am sending this json to cloud messaging (with proper headers) and want to get notification on my device, but it does not appear on my phone. I think that maybe i am missing channel id initialization for Android ?
*Additional info
If i send "notification" payload with title or body it is receiving, but i dont want to use "notification" payload. I want to have "data" payload only
{
"to" : "my device token",
"mutable_content" : true,
"content_available": true,
"data" : {
"content": {
"id": 100,
"channelKey": "basic_channel",
"title": "Huston!\nThe eagle has landed!",
"body": "A small step for a man, but a giant leap to Flutter's community!",
"notificationLayout": "BigPicture",
"largeIcon": "https://media.fstatic.com/kdNpUx4VBicwDuRBnhBrNmVsaKU=/full-fit-in/290x478/media/artists/avatar/2013/08/neil-i-armstrong_a39978.jpeg",
"bigPicture": "https://www.dw.com/image/49519617_303.jpg",
"showWhen": true,
"autoCancel": true,
"privacy": "Private"
},
"actionButtons": [
{
"key": "REPLY",
"label": "Reply",
"autoCancel": true,
"buttonType": "InputField"
},
{
"key": "ARCHIVE",
"label": "Archive",
"autoCancel": true
}
]
}
}
In order to define a notification channel you have to go to your AndroidManifest.xml and within the application component add this meta:
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="#string/default_notification_channel_id"/>
then in your strings.xml file put the channel id like this:
<string name='default_notification_channel_id'>Channel ID</string>
After doing this, you can define your channel id in the FCM Console.
As simple as this. Just put your android channel name here below and it works with a charm:
"notification": {
"body": "Test notification",
"title": "Test Test Test",
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"sound": "your_custom_sound"
"android_channel_id": "channel_id_youcreated",
},
'to':
"",
},
Sound file name is not necessary in the above given notification payload if you assigned that sound to your notification channel thru MainActivity.kt or java file. However, it is necessary for older Android versions as they will use the sound file directly. Put your file inside res/raw folder.

Unable to open the app when clicking on push notification using PhoneGap plugin?

I am able to receive the notification with action button using phonegap plugin. However, I am not able to open the app when I click on notification.
I have checked following parameter in config.xml
android:launchMode="singleTop"
I have tried various payloads. I am using postman to send these notification. I am able to open the app when i use following payload(Supported by FCM) but I don't receive action buttons.
{
"registration_ids": ["dG7v71qgTtQ:APA91bGzfypc_bf-YZ_Gzayqoit4b4DeAZpCaTvPq5Cw3XqTClEFVkgTvvIZCkJVPXIa6-iLnzSrLuFO39SN-kCypBkkxklBIkf4qyYb1WWRZV4qVpR7sMKsNE3tNqtvd6m-ierZxRT6"],
"notification": {
"title": "My title",
"message": "My message."
},
"data": {
"actions": [
{ "title": "Accept", "callback": "app.accept", "foreground": true},
{ "title": "Ignore", "callback": "app.ignore", "foreground": false}
]
}
}
When I use following payload I receive action buttons notification. But not able to open the app when user clicks the notification!
{
"registration_ids": ["dG7v71qgTtQ:APA91bGzfypc_bf-YZ_Gzayqoit4b4DeAZpCaTvPq5Cw3XqTClEFVkgTvvIZCkJVPXIa6-iLnzSrLuFO39SN-kCypBkkxklBIkf4qyYb1WWRZV4qVpR7sMKsNE3tNqtvd6m-ierZxRT6"],
"data": {
"title": "AUX Scrum",
"message": "agenda.",
"actions": [
{
"icon": "emailGuests",
"title": "EMAIL GUESTS",
"callback": "emailGuests",
"foreground": true
},
{
"icon": "snooze",
"title": "SNOOZE",
"callback": "snooze",
"foreground": false
}
]
}
}
Expected result: User should be able to receive action button push notification and clicking notification opens the app.
Actual Result: User receive action button notification, but on clicking notification, Notification is closed and app is not opened( Even if App is in Foreground or background)
There was a plugin issue. I reinstalled the plugin and it worked.

When I removed "click_action": "FCM_PLUGIN_ACTIVITY" then Ionic 1 app's push brakes

Firebase API push payload from backend :
{
"registration_ids": [
"IKSiok9Zpip5cDcebQ67wc7TnpDuhMAFJm1xdGGI44s48JbXEu5iYa"
],
"notification": {
"body": "Push Test Facility Category",
"title": null,
"icon": "myicon",
"sound": "mySound",
"vibrate": 1,
"Badge": 1,
"click_action": "FCM_PLUGIN_ACTIVITY"
},
"data": {
"message": "Push Test Facility Category",
"title": null,
"b": "22",
"id": "2",
"category_name": "Restaurants",
"h": "1",
"p": 1,
"type": "2"
}
}
fcm.service.ts
fcmListeners() {
this.firebase.onNotificationOpen().subscribe(async (data: any) => {
if (data.tap) {// when user tapped the background notification
} else { // Received in foreground
}
});
}
Can you tell me why the app doesn't open when I used the above payload and app is in the background? This is the behavior on an Android device. But no issues on iOS device.
If I use a firebase console cloud message (i.e. dashboard) then no issues there. i.e. it opens the app even in the background on android device. Any clue?
Note: I use the firebase plugin here.
Update: When I removed this "click_action": "FCM_PLUGIN_ACTIVITY" then it works fine on Ionic 4 apps. But it is not working on Ionic 1 app. Any clue?
Ionic 1: It works with this "click_action": "FCM_PLUGIN_ACTIVITY".
Ionic 4: It works without this "click_action": "FCM_PLUGIN_ACTIVITY"

How to config Firebase Push notification Message

I have found various examples on how to configure the message json for push notifcations on firebase for android and ios. But I have a problem, that not all push messages arrives to my client apps. I have noticed that on different android versions it work in a different way. Some of them, doesn't receive any message, some of them without the configured ringtone, some of them only with the default ringtone and some works fine. On client side I think every thing should be fine. I'am using xamarin forms for that. My message json looks like this. I have read now that I should remove the notification tag but it works then for older androids?
{
"to": "/topics/MYTOPIC",
"notification": {
"title": null,
"body": "test",
"sound": "de900",
"content_available": true
},
"priority": "high",
"data": {
"missionGuid": "",
"eventGuid": "",
"messageGuid": "e3ab4c34-125b-4ea7-abf7-3ee8fe1453ce",
"ric": "199900",
"title": null,
"body": "test",
"priority": "high",
"sound": "de900"
},
"android": {
"priority": "high",
"notification": {
"title": null,
"body": "test",
"sound": "de900",
"content_available": true
},
"data": {
"missionGuid": "",
"eventGuid": "",
"messageGuid": "e3ab4c34-125b-4ea7-abf7-3ee8fe1453ce",
"ric": "199900",
"title": null,
"body": "test",
"priority": "high",
"sound": "de900"
},
},
"apns": {
"headers": {
"apns-priority": 10
},
"payload": {
"aps": {
"alert": {
"title": null,
"body": "test"
},
"sound": "de900"
}
}
}
}
Setting the "priority" and "sound" in the notification payload never helped me. The behavior of this was very strange.
I decided to use only Data payload and handle both background/foreground messages inside onMessageReceived method and show your custom notifications.
After this I was able to show the notifications with the highest priority, pop-ups and sound.
Read more about Firebase data messages here
As far as I know, setting "priority": "high" is the only thing you can do to make sure the notifications deliver immediately. If they still can't receive anything, it's probably something on the client's side.
For the ringtone, supposedly, "sound": "WHATEVER" is the supposed to specify the sound, but again, because of the different OEMs and system variations, it could be more consistent to just send a data message and push out the notification yourself upon receiving, but you should know that even that probably won't guarantee either deliver or ringtone.
The fact that on some devices this works fine (hopefully the majority of them), indicates you probably have a correct set up for the configuration, and the best you can do is to handle the notification yourself and maybe have special cases for specific devices.

Categories

Resources