Firebase Messaging Flutter - Decrypt the notification body - flutter

I'm having a situation with Firebase Messaging in flutter. I need to decrypt the notification body - which is an encrypted chat message - before displaying it. I was able to do it on the foreground notifications, but not on the background and terminated ones.
I tried decrypting it on
FirebaseMessaging.instance.getInitialMessage().then((message) => myHandler)
and on
FirebaseMessaging.onMessageOpenedApp.listen(myHandler)
but it doesn't seem to run through this code.

Related

Error sending notification: UnimplementedError: sendMessage() is not implemented

I want to add firebase push notification in my flutter app and sending notification through flutter web admin,App is working perfect but web is not sending message

I already get fcm key of ever users,How to send notification to another user with firebase cloud messaging?In dart

I have Fcm key
and working when i put fcm trial of cloud messageing in firebase
I tried but only got same device notification,
I am expecting that when I send a message to another user The other user need to get a notification while the app is not opened

Duplicate notifications with different sounds - push notification remote

I am trying to add the custom sound in the push notification. I have added the showNotification in the background handler on the client-side (flutter), but now when the application is in the background or terminated I receive duplicate notifications, one with default sound and the other with my custom sound. Can anyone tell me how to stop showing the default background notification?
You're getting the duplicate notification because
you're sending a notification message and it is automatically displayed by the FCM SDK and,
you're implementing a custom notification display yourself.
The solution is to send a data message instead of a notification message.
With FCM, you can send two types of messages to clients:
Notification messages, sometimes thought of as "display messages."
These are handled by the FCM SDK automatically.
Data messages, which
are handled by the client app.
Source

How to hide a new message notification when user is actively chatting with the sender in flutter

I am implementing a chat feature in my flutter app. I use FCM to send a notification when a new message comes. I propagate the FCM message to flutter local notification when the notification came while the app is in the foreground. My problem is I don't want to show the local notification when the user is actively chatting with the sender.
I have firebase messaging configuration in app.dart and I have another stateful widget to show the message details and chat. I will get fromUid from notification data. I have also open chat message UID's in the message details widget. I am trying to compare these two UIDs values from notification and message detail widget and if the UIds are the same don't notify.
I try using change notifier and RouteObserver but it's not working fine. I will love any help and recommendations.
I have implemented a similar feature in my app. This is what I did.
I am using flutter and hive for local storage.
Do this when entering chat view
Hive.box("settings").put("currentChatId", xxx)
And on popping the page, set it to null again
On receiving notifications, before showing local notification you can just use .get("currentChatId")!= null && id==notificationId to check if it should show it or not.

Send Notification as message with Firebase Cloud Messaging in Swift

I'm trying to create a Chat App. When the app enters background and if he receives a message, then a notification must appear.
What I understand is that FIRMessaging.sendMessage() sends something to the cloud. But how the other device is gonna receive it ? It cant be continually looking for messages that are targetted to him...
I would like to understand how to use this fonction and what are the parameters to pass in it. So far and with the current documentation, I couldnt do it.
[[FIRMessaging message]sendMessage:(nonnull NSDictionary *)message
to:(nonnull NSString *)receiver
withMessageID:(nonnull NSString *)messageID
timeToLive:(int64_t)ttl;
What should I put in the receiver ? It's userId in firebase ? or what ?
In the exemples they talk about SENDER_ID + "#gcm.googleapis.com"
which confuses me cause it looks like it's either my Id or the Id of the firebase App..
I cant even figure out if i'm trying to send an upstream or downstream message (dont understand)
Well all I can say is that I really get my head around it...
https://firebase.google.com/docs/cloud-messaging/upstream#handle_upstream_message_callbacks_1
Thanks!
Firebase Cloud Messaging and Firebase Notifications (which is built on Firebase Cloud Messaging) handle this automatically for you. From the documentation of Firebase Notifications:
When your app is in the background on a user's device, notifications are delivered to the system tray. When a user taps on the notification, the app launcher opens your app. If you want, you can also add client message handling to receive notifications in your app when it is already in the foreground on the user's device.