I'm sending notifications to certain users via the postman. The notification successfully reaches the device. However, it won't show in lock screens as well as a pop up from the top of the screen when the user is actively using the device (like WhatsApp notifications). How to send the notification with more priority to Firebase using the REST API?
{
"notification":{
"image":"",
"sound":"default",
"title":"Order Packing",
"body":"We are packing your order"
},
"data":{
"linkType":"order"
},
"default_sound":true,
"to":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"tag":"orderStatus",
"priority":"high",
"notification_priority":"PRIORITY_MAX"
}
Related
I'm using Capacitor for my App, I have an use case similar to whatsapp, when users receive a new message if your app is in background, you receive FCM notification in the notification tray, later if user open that particular chat directly by opening the app(without clicking on the notification), i'd like to clear that notification from the notification tray.
so here's what I thought
get active notification
find the active chat notifications by filtering extra data sent by FCM
clear those notifications programatically
however android's notificationManager.getActiveNotifications doesn't seem to provide access to FCM data.
below is the payload i'm posting to FCM(i want to use chatId and type in data section to clear active notifications).
{
"android": {
"priority": "high"
},
"notification": {
"title": "you have a new message from XYZ",
"body": "hello"
},
"data": {
"messageId": "62971793-0111-4c9b-bbb2-bb78262a0543",
"chatId": "631e162f5f286c23d13e06d5",
"type": "CHAT_NEW_MESSAGE"
},
"token": "fcmToken"
}
Here's the capacitor plugins Android Logic to get the delivered/active notification.
how can I achieve above use case?
I am sending push notifications from my server (to a firebase token and not to a topic). I do not differentiate between the platforms, the server just sends the JSON via RestTemplate (Spring Boot App).
If I prepare it for Android, it works, but it does not for for iOS. But if I prepare it for iOS, it does not work for Android.
The case is: I want the notification and the background process (It should display the notification in any case foreground/background/killed and it should take key-value pairs from the data payload).
The problem is: If I use notification in my JSON, the notification would be displayed on iOS and on Android but just the iOS can handle the payload (in foreground/background/killed state). If I remove the notification tag in JSON, then everything works fine (Android and iOS receives the payload in all states, but the iOS does not display the notification).
In Android you can build the notification client side (like me), but in iOS its not possible.
So, how can I send a FCM (JSON) with a firebase-token and it is platform-independent? Both can handle it properly, both receive the payload and displays the message and payload should be handled in every state.
This works on android and displays the message (built client side) but does not work for iOS
{
"content_available": true,
"data":{
"action":"bla",
"value":"true",
"id":"111111"
},
"android":{
"priority":"high"
},
"apns":{
"headers":{
"apns-priority":"10"
}
},
"to":"<MY_FCM_TOKEN>"
}
This displays the FCM for android and iOS, but handles the payload just on iOS
{
"notification":{
"sound":"default",
"title":"Test Title",
"body":"Message of FCM"
},
"content_available": true,
"data":{
"action":"bla",
"value":"true",
"id":"111111"
},
"android":{
"priority":"high"
},
"apns":{
"headers":{
"apns-priority":"10"
}
},
"to":"<MY_FCM_TOKEN>"
}
Or is it possible to declare the notification-tag just for iOS?
Or is it possible to create notifications also client side in iOS when a payload receives?
Before sending a notification on the Server side I am checking whether the the platfomr is iOS or Android by using google's method:
https://iid.googleapis.com/iid/info/IID_TOKEN
Which on success returns a JSON with a 'platform' parameter.
You can find more info here
We are using firebase to send notifications to both Android and IOS devices from server and we are using legacy FCM to send notifications.
But when our app is backgrounded notification is handled by system itself and thus we couldn't handle it by app. So we need to add data to notification to handle the notification by application itself on android side.
But due to we also have ios devices we couldn't remove notification from the pattern.
Is there any way to send data to Android devices and notification to IOS devices?
Also you may find the pattern that I mentioned at below.
{
{
"registration_ids":[
],
"content_available":true,
"priority":"high",
"data":{
"title":"",
"text":"",
"badge": 1,
"sound": "default"
},
"notification":{
"title":"",
"body":"",
"badge": 1,
"sound": "default"
}
}
You will have to map the FCM Registration ID with the OS Type and store it somehow. Now when you are sending the notifications, based on the OS Type, you will change the body structure for the notifications.
I'm trying to send a payload using GCM that can be handled on the background or foreground by clients using Android and iOS. The messages are delivered to clients using both platforms that are subscribed in a topic.
Because I need the iOS app to handle the data even when the app is on the background or closed, I'm setting "content_available": true, which works as expected on iOS.
However, when I add that parameter, Android does not handle the received data and instead displays a blank notification.
Here's an example payload:
{
"to": "/topics/946",
"content_available": true,
"data": {
"time": "2016-02-04 18:33:08",
"message": "Hello",
"msgType": "chat",
"senderId": "50",
"senderName": "John"
}
}
The documentation says that data messages should wake the Android app anyway:
On iOS, use this field to represent content-available in the APNS
payload. When a notification or message is sent and this is set to
true, an inactive client app is awoken. On Android, data messages wake
the app by default. On Chrome, currently not supported.
What am I doing wrong?
EDIT: I've already tried using "priority":"high", which does not make any difference.
This question already has answers here:
Google Play Services 8.4.0 breaks Google Cloud Messaging for Android if iOS is also used
(3 answers)
Closed 6 years ago.
For Push notifications we are using GCM(Google Cloud Messaging). It was working fine when we used play-services:8.3.0 . We process push notifications with our own receiver. After upgrading to com.google.android.gms:play-services:8.4.0
Push not coming to my myGcmListenerService, instead its shown by itself in notification bar. Also it shows this error in Log
GcmAnalytics: Error while parsing timestamp in GCM event.
With 8.3.0 we received push like this:
Bundle[{gcm.notification.e=1, google.c.a.ts=234343426, gcm.notification.badge=1, gcm.notification.sound=default, gcm.notification.sound2=default, gcm.notification.body=John M # Cords, Wires And Cable Ftu, gcm.notification.data={"name":"new_chat_message","message_id":490666,"channel_id":5366}, google.c.a.e=1, collapse_key=com.domain.app.debug}]
With 8.4.0 pushes coming like this:
Bundle[{notification=Bundle[{sound2=default, e=1, body=John M # Cords, Wires And Cable Rrr, data={"name":"new_chat_message","message_id":490641,"channel_id":5366}, badge=1, sound=default}], collapse_key=com.domain.app.debug}]
In your server just send the e field as zero inside the notification field.
{
"to": "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
"content_available": true,
"notification": {
"e": 0
},
"data": {
"key": "value"
}
}
And then in android the bundle will be:
Bundle[{gcm.notification.e=0, key=value, ...}]
So now if your app is in background it will not show the notification by itself and will receive the bundle in your GcmListenerService.
But if you have both notification and data payloads and your app is in background, it will show the notification by itself, as described here.
Hybrid messages with both notification and data payload
App behavior when receiving messages that include both notification and data payloads depends on whether the app is in the background, or the foreground —essentially, whether or not it is active at the time of receipt.
When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notification.
When in the foreground, your app receives a bundle with both payloads available.