I implemented the push notification on Android through Firebase, I have a problem that I haven't found an answer anywhere, I'm getting my push perfectly, but when I receive a notification with the application closed, the default sound is played, but the message does not slide on screen, if I go to the notifications my message is there, but it does not slide as soon as it arrives on the device is this a parameter of the firebase API or is it an implementation in the code? In the app's permissions, I'm allowed to slide messages. Has anyone come across this?
This is the body of the request for the legacy firebase api.
POST - https://fcm.googleapis.com/fcm/send
{
"notification": {
"body": "my body",
"title":"my title",
"sound": "default"
},
"data":{
"click_action": "",
"type": "",
"action":"",
"content":""
},
"priority": "high",
"to": "token device"
}
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 trying to send notifications to both Android and iOS devices using FCM. The front end was coded with Flutter. I am working with Typescript/NestJS at the back end. For some reason, iOS devices receive all the notifications with a push notification/pop-up but Android devices sometimes don't. Strangely, the notifications ALL arrive at the test device INBOXES. It's just that sometimes, Android devices do not show a pop-up/push notification.
Targeting users thru a Firebase topic works as expected: push notifications do arrive for Android and iOS. I do have to find and filter out the users to target before sending the target device IDs to FCM. I am confident my filters are correct. The notifications arrive in the app inbox for both Android and iOS after my filtering. Also, changing the device ID/token in my database causes an error from FCM:
{"code":"messaging/registration-token-not-registered","message":"Requested entity was not found."}
If I revert the data to its original values, the app runs fine. I've checked and compared the data I pass to Node.js' FCM module and it looks fine. Here, messaging is an instance of firebaseAdmin.messaging().
param = {
"android": {
"data": {
"id": "67bcd478-f643-4c9e-848a-be354a6b85d4",
"icon": "default",
"title": "Test",
"body": "Direct From Playground"
}
},
"apns": {
"payload": {
"aps": {
"id": "67bcd478-f643-4c9e-848a-be354a6b85d4",
"icon": "default",
"title": "Announcements",
"body": "Direct From Playground",
"alert": {
"title": "Announcements",
"body": "Direct From Playground"
}
}
}
}
}
messaging.sendMulticast({
tokens: value as string[],
...param,
});
Again, the code above sometimes successfully triggers push/pop-up notifications on Android devices but ALWAYS on iOS. Could this be a problem for the front-end handling of my data? Am I missing some parameters?
I am using firebase messaging to send notifications to users in flutter application, and everything is working fine when I am sending notification from postman (notification always shows), but then when I want to send the same notification from my backend server, notification not showing on device. On server logs I can see that notification was send with success like this:
{
"multicast_id": XXXXXXXXXXXXX,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "XXXXXXXXXXXXX"
}
]
}
So it means it was correctly send to messaging services, but push notification not firing on device.
Sometimes when I open app (going to foreground of application) then notification somehow shows, but I need users to see notification always, especially when their app is closed.
I am sending notification with high priority so this is not an issue.
Any help, what could be potential issue with this?
My request to FCM:
POST: https://fcm.googleapis.com/fcm/send
Authorization: key=xxxx_MY_KEY_XXXXX
Content-Type: application/json
{
"to": "xxxxxMY_FCM_TOKEN_xxxxxx",
"mutable_content": true,
"content_available": true,
"priority": "high",
"data": {
"content": {
"id": 106,
"channelKey": "remote_chann",
"title": "Hello",
"body": "test",
"notificationLayout": "Messaging"
}
}
}
As per your data send with fcm is sending only data object not notification object as per the fcm to wakeup it self you need to send notification object along with data object.
https://firebase.google.com/docs/cloud-messaging/concept-options
im trying to send push by http to Huawei Devices with Huawei consolé integration, but the documentation is confuse, and i'm not really sure how to build my body to send
I have this, but only works for foreground, if the app is in background or terminated, the push isn't working
This is the portar i'm following https://developer.huawei.com/consumer/es/doc/development/quickApp-Guides/quickapp-access-push-kit#dataDesc
{
"validate_only": false,
"message": {
"data": "{title: Hello! 1, description: Hello, shirley!, params: { key1: test1, key2: test2}, ringtone: {vibration: true, breathLight: true}}",
"android": {
"title": "Hello! 1",
"body": "Hello, shirley!",
"params": {
"key1": "test1",
"key2": "test2"
},
"click_action": {
"type": 3
}
},
"token": [
"IAAAAACy0irbAADqfnlY9pfEgoWWoIzgCBXQzPol8CTNzV6i3V5byP7cIhuU74vovAwysjkI_XMwowYj1sv5SrhXRi-sYXB5OrplLHEB02LO0pKHcA"
]
}
}
The conditions received by the Push notification do not need to be run in the foreground.
According to the Docs,You can send push messages in either of the following ways:
Select target users in AppGallery Connect. In this case, messages can be pushed to both quick apps on the live network and those running on a quick app loader.
Send push messages to a large number of users in batches by invoking server APIs. In this case, messages can be pushed to both quick apps on the live network and those running on a quick app loader.
Conditions for a quick app to receive push messages are as follows.
I have some issues with sending custom push message using Firebase Cloud Messaging with my data.
On iOS I have created Notification Service Provider that controlls every incoming notification but I had to add "notification" field with title and body in push request to Firebase. If there was no "notification" field then if app was turned off/killed then I couldn't receive message.
On Android I have my FirebaseMessagingService where I receive messages (and I can decide what to do with it) but if "notification" field is present in Firebase request then FirebaseMessagingService is not receiving message but notification shows automatically with title and body from "notification".
I've found some docs from Firebase about platform-specific messages
(When to use platform-specific keys) and I though to add notification only for iOS platform. I have tried few approches described in link above and here Creating the Remote Notification Payload / Payload Key Reference
Below some examples of JSON I've tried to send but I always get error InvalidParameters: Invalid notification payload (I've tried all possibilities with fields apns, payload, aps, alert)
{
"to": "xyz................", //single device with android or ios
"mutable_content": true,
"data": { "field1": "value1" [.......] },
"apns": {
"payload": {
"title": "Some message title",
"body": "Some message body",
"sound": "default"
}
}
or
{
"to": "xyz................", //single device with android or ios
"mutable_content": true,
"data": { "field1": "value1" [.......] },
"apns": {
"payload": {
"aps": {
"title": "Some message title",
"body": "Some message body",
"sound": "default"
}
}
}
etc.
The purpose is to receive data in my app and decide how to handle it - depending on incoming data I want to show my own notification or make some custom action in app.
Is it even possible to send platform-specific message to iOS with notification/alert and without it to Android? If so - how?