I am developing a meteor app with version meteor version 1.5. I added the raix:push package and its sending notfications as desired. But if more than one notification is sent, the new notification overlaps on the previous one. Whereas I want it to be displayed as an inbox.
I tried using this :
`Push.send({
from: 'appName',
title: 'New notification',
text: 'test',
badge: 12,
gcm: {
style: 'inbox',
summaryText: 'There are many notifications'
},
query: {
userId: user.userId,
}
});`
But it doesn't work. Notifications are sent as per before only.
On checking again, I saw that nothing is being entered in the gcm field of notification collection.
Another thing I noticed is that query is stored as a string whereas gcm is an object. Does that have an affect?
Also, I would like to route to a specific page onCLick on the notification. How to add that?
Related
I have an app which subscribes to a topic in Firebase Messaging. (for example the topic is "test").
and with cloud functions I successfully send a notification to all devices subscribed to the "test" topic.
I need when the user taps on the notification to open the app in the main screen.
this is my cloud function:
.document('testdocument/{testdc}')
.onCreate((snapshot, context) => {
return admin.messaging().sendToTopic('test', {
notification: {
title: "APP MON",
body: "Check Mon!!!",
clickAction: 'FLUTTER_NOTIFICATION_CLICK',
},
});
});
am I missing something?
P.S: The notifications show fine (with the Icon of my app and the message I need, they just don't do anything) - also, this is needed only for ANDROID
many thanks in advance.
The correct parameter is click_action.
Has anyone actually used FCM - FireBase Cloud Messaging to create device push notifications with interactive action buttons that runs when the app is is background/closed?
The goal is for the user to be able to react to the notification like WhatsApp, Messenger...
The app is cordova so anyone with experience on that would be great.
I have all the FCM setup already done and the backend working.
I already can trigger a simple notification "title+body+icon/message"
According to FCM, the payload can contain the notification section, where the OS will handle the notifications, but nothing is said about it being able to contain buttons. (So it is not that interesting).
However it's possible to use the "data" section with the values key pairs that are sent to the app to generate a local notification with the buttons, on the onMessage callback.
[UPDATE]
The push service with data does not trigger the app to create the local notification if the app was swiped (some brands kill the app when swiped from recent apps - stopping javascript execution). Conclusion: For the FCM data payload message to work, must capture the push broadcast message event (native side) with a service, and then create the notification generation (native way) with buttons based on that data payload. FCM does not support push notifications with buttons.
import { getMessaging, getToken, onMessage } from "firebase/messaging";
import { getDevice } from "framework7/lite-bundle";
function setupPushNotification(getTokenCallBack,onMessageCallBack) {
const device = getDevice();
if (device.cordova) {
FirebasePlugin.getToken((token) => getTokenCallBack(token));
FirebasePlugin.onMessageReceived((message) => {
if (message) {
onMessageCallBack && onMessageCallBack(message);
}
},function(error){
console.error(error);
});
}
}
And then to setup the whole process, creating a local notification object with buttons previously defined:
cordova.plugins.notification.local.addActionGroup('yes-no', [
{ id: 'yes', title: 'Yes', foreground: false },
{ id: 'no', title: 'No', foreground: false }
])
setupPushNotification((deviceToken)=>{
//update device token on backend database
},
(message)=>{
//This is the onMessageReceived message
//Create a local notification for exaple using the local notification cordova plugin
cordova.plugins.notification.local.schedule({
title: "Test Title",
text: "Test Body",
actionGroupId: 'yes-no',
})
})
I'm using these cordova plugins
"cordova-plugin-local-notification": "^0.9.0-beta.2",
"cordova-plugin-firebasex": "^14.2.1"
You can do almost anything with cordova, that any native app does.
Ever tried cordova-plugin-firebase-messaging? I have been able to add a chat reply text box with send button in the notifications.
you can also refer to How to add action buttons to ionic push notifications?
We need to run a repeat notification every day 7 am and the content is not static it is dynamic
content needs to fetch from API
is there any way to do it in flutter for both ios and android
With out doing anything from server-side?
We used https://pub.dev/packages/flutter_local_notifications and not solved the issue?
We are developing an app for an existing website and clients have all the APIs and they are not using FCM. They will not do any changes in server-side and they highly recommend to handle it's from the app side only.
If we use Firebase messaging lib is that possible to do notification and API call in background with in the ios and android app?
Use firebase functions with pubsub. Use this code in the firebase function.
const admin = require('firebase-admin');
const fcm = admin.messaging();
exports.dailyNotification = functions.pubsub.schedule('0 7 * * *')
.onRun((context) => {
//tokens need to be unique to send notifications per device
//you can call data from firebase firestore to change the notification contents
const payload = admin.messaging.MessagingPayload = {
notification: {
title: 'Notification title',
body: 'This is a notification message',
icon: 'your-icon-url',
click_action: 'FLUTTER_NOTIFICATION_CLICK'
}
};
/*this token you need to save from flutter. You need it only when you
need to send specific notification to the specific device*/
fcm.sendToDevice(tokens.token, payload);
});
Use this package in flutter
Firebase messaging lib
Learn it from here that how to use firebase messaging notification.
Flutter firebase notification tutorial
Let me know if you have any questions.
i experience pretty weird thing in my android app. In some unknown for me cases sometimes blank notification apperas in notification bar, without any title, body and with default gray color. The only filled thing is icon, which is my default application icon(from manifest).
There is only one place in project when i create notification manually - intent service that sends data via rest api. Notification have his own icon (different than default), color, text, progressbar and works fine when service is running. I have not configured any Cloud Messaging or push notification in this project.
I spent a lot of time and i have no idea why blank notification described above appears. I will be grateful for any hint how to prevent it.
Yes, I am also facing this issue, when the app is closed that time notification will appear like this. I am resolved this issue in server side.
There are two types of messages in FCM (Firebase Cloud Messaging):
Display Messages: These messages trigger the onMessageReceived() callback only when your app is in foreground
Data Messages: Theses messages trigger the onMessageReceived() callback even if your app is in foreground/background/killed
Firebase team have not developed a UI to send data-messages to your devices, yet.
refer this link to achieve
https://fcm.googleapis.com/fcm/send
And the following headers:
Key: Content-Type, Value: application/json
Key: Authorization, Value: key=<your-server-key>
Body using topics:
{
"to": "/topics/my_topic",
"data": {
"my_custom_key" : "my_custom_value",
"other_key" : true
}
}
Or to send it to specific devices:
{
"data": {
"my_custom_key" : "my_custom_value",
"other_key" : true
},
"registration_ids": ["{device-token}","{device2-token}","{device3-token}"]
}
NOTE: Be sure you're not adding JSON key notification
NOTE: To get your server key, you can find it in the firebase console: Your project -> settings -> Project settings -> Cloud messaging -> Server Key
I am using Firebase Cloud Messaging HTTP Protocol to send push notifications to my application using postman for testing.
I am using the following code to send the push.
{
"notification":{
"title":"Title",
"body":"this is a notification to a specific topic",
"sound":"default",
"click_action":"FCM_PLUGIN_ACTIVITY",
},
"data":{
"action":"ping"
},
"to":"/topics/Topic_1",
"priority":"high"
}
and I am using this code to handle the notification on my app:
FCMPlugin.onNotification(function(data){
console.log(data);
if(data.wasTapped){
//Notification was received on device tray and tapped by the user.
alert('notification tapped'+ JSON.stringify(data) );
}else{
//Notification was received in foreground. Maybe the user needs to be notified.
alert('application is open'+ JSON.stringify(data) );
}
});
it is all working except i cannot get the title and the body to use them in my application, all I am getting is the following:
Object {wasTapped: false, action: "ping"}
I cannot find a way to get the notification title and body.
I know I can copy them to the data section but that's not logical its a dirty workaround
so any idea how to get the notification data?
thank you.
Basing from the behavior shown, I'm presuming that the client platform is Android. If so, then this is working as expected.
When sending a combination of both notification and data in your message payload, the Android System tray will be the one to handle the values in notification. The dirty workaround you mentioned is the only workaround so far -- a workaround that I actually suggested on one of my answers as well.