I want to send notification at night to the user. I do not want to play any sound, I just want the user to see it on his status bar when he wakes up.
How can I send push notification without playing sound on the user device ( both android and ios)?
From Firebase Notification web console:
you can set sound = disabled in the advanced option
Extra tip: you can also set a delivery type relative to the device: like 8am on the user timezone.
Using Firebase Cloud Messaging API:
you can send a notification-message without sound:
to do this do not specify any sound parameter in the notification: { title: '' .. } json
or you can send a data-message: data: {key: value, key2: value2, ..}
this message will not trigger any automatic notification, only your app callback. then you add code to create the notification in the way you prefer.
List of parameters for notification-messages:
https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support
Read more about notification-messages vs data-messages here:
https://firebase.google.com/docs/cloud-messaging/concept-options
Related
I would just like to receive the notification data via the OnMessageReceived method and then display a custom notification with Unity's MobileNotification or UTNotification.
Any information in the notification property of a message is automatically handled by the system when the app is not active. If you don't want the system to automatically display a notification, make sure that your message contains no notification property. Data only messages are not displayed by the system automatically.
For more on this, also see the Firebase documentation on message types.
While it is possible to add data properties to an FCM message that is sent through the Firebase console in the Custom data section of the Additional options, there is no way to send a data only message. Messages sent through the Firebase console will always have a notification property, which is what triggers the system to display them.
If you want to send data-only messages, the simplest way is through a CURL command as shown here: How can I send a Firebase Cloud Messaging notification without use the Firebase Console?
Thanks to Firebase and FlutterFire, it's easy to send regular notifications from the servers to the users' devices. Those notifications include a title, a body, and an image url. But what about creating a no-that-simple notification, like Telegram's or WhatsApp's?
The simple question is to avoid sending a Notification from the server, and instead set the data field to the push message. But according to the FlutterFire documentation:
Data only messages are considered low priority by devices when your application is in the background or terminated, and will be ignored
So, it sounds like if we want to have a reliable delivery system, we should add a Notification to our push messages. But that notification is so simple. And, again, according to the documentation:
If your message is a notification one (includes a notification property), the Firebase SDKs will intercept this and display a visible notification to your users (assuming you have requested permission & the user has notifications enabled)
So: If I want a reliable system, I have to send Notifications, but I do it, I can't tell FlutterFire to use my custom notifications.
So the question is: how to show custom notifications with FlutterFire?
What I want to achieve is something like this:
I'm going to try setting the priority of the push notification.
You can however explicitly increase the priority by sending additional properties on the FCM payload:
On Android, set the priority field to high.
On Apple (iOS & macOS), set the content-available field to true.
On the server side code, it looks like:
message.setAndroidConfig(AndroidConfig.builder().setPriority(AndroidConfig.Priority.HIGH).build());
message.setApnsConfig(ApnsConfig.builder().setAps(Aps.builder().setContentAvailable(true).build()).build());
I use nativescript-vue and this plugin for sending push notifications:
nativescript-plugin-firebase,
How do i send an image along when i send a push notification?
In my nativescript-vue project i receive the notification like this:
firebase.init({
showNotificationsWhenInForeground: true,
onMessageReceivedCallback: async (message) => {
})
How do i show an image in the notification?
I have tried with including image: "url" and that dosnt work. I think there is way to show a image in the notification because on the firebase panel there is an option to send along a image.
The firebase notification plugin only acts as a receiver and handler of notifications in this case. If you want to send a remote notification with image, you are going to do that with your notification sender; and in this case on Firebase.
If you just want to quickly send or test a push notification with an image, you can do so by going to Firebase Console > Cloud Messaging.
Then just add your image in the respective field.
Now, in most cases in production you would want to do this progmatically on your backend instead of going to Firebase Console. You can do that by using Firebase FCM SDK.
In our case, we usually do it via API calls something like:
POST https://fcm.googleapis.com/fcm/send
BODY
{
"to": "/topics/user_{{userId}}",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message"
}
}
Header should include a key "Authorization" with value:
key=<YOUR_FCM_KEY_HERE>
You can get your FCM key by going to Firebase Console > Project Settings (the gear) > Cloud Messaging. You can check this doc for more details on sending.
Lastly, if you really want to handle the notification image via your app (not suggested), you can force so by using a local push notification by force handling the remote push notification and doing a local push notification with your own desired image.
I am able to successfully send from Firebase push notifications and receive them on mobile. I can do everything (so far) using the official firebase_messaging package.
In my Flutter app there's a variable called bool isAdmin which can be true or false, it depends. I need to make it so that some notifications are seen only by people that are actually admins.
In other words, certain push notifications can be seen only if isAdmin = true. How can I do this?
POSSIBLE SOLUTION
I am thinking to add a flag in the body payload of the push notification called adminPush which can be true or false. But then, how can I read this field and prevent the notification to appear?
According to this the notification block of the push notification gets displayed by the push notifications SDK itself if the app is backgrounded, so one way to fix this is sending only data block, omitting notification block altogether for this particular push notification type, and displaying a local notification if isAdmin = true.
I had read that not to add notification node in the body of the request, and I tried to send without notification node but it seems that the message not received but when I add the notification node it work well
So, what is the difference notification node and data node in Firebase cloud messaging?
{
"to": "/topics/some_topic",
"data": {
"key_1" : "some_value",
"key_2" : "some_value"
},
"notification":{
"body" : "some_message"
}
}
Is there any link to doc I can read ?
The data node is used for sending notification if the application is on the background/foreground and in some phones if it is also killed.
The notification node is used for sending notification if the application is on the foreground. If it is in the background you wont receive the notification.
The best option I found is to use data node alone.
Also it is explained very well in this link: The FCM messages types
Notification node (a.k.a Notification messages)
When sent, this will receive a notification on the device, regardless of whether the app is in foreground/background/terminated state, but the notification will be shown only when the app is not in foreground. You can bundle a data payload with this of upto 4 KB. The upside is that you do not have to worry about generating a notification every time, the libraries take care of that. The downside is that there is no way not to show the notifications, for eg when you want to do something silently.
Data node (a.k.a Data messages)
When sent, this will fire up all the same callbacks as a normal notification node would, the only difference being that a notification won't pop up on its own, you are the master of your own callback! This is useful for when you want to do something silently, like refresh the cache, update the database etc. As a data node will have the data payload and will fire up a callback at any state of the app, you can generate a notification on your own and fire it up. This gives you the freedom to design your notification however you want!