I am using firebase and flutter_local_notifications package to show the notifications sent from api (laravel) and when app is closed (background mode) the notification is repeated but in foreground it appears once
This is my code
https://github.com/KamlaSaad/Notification/blob/main/not
There are two types of messages: notification and data.
Notification messages are handled by the FCM SDK automatically. Most likely the first one comes from SDK and the second one from your handler.
Notification messages which arrive in the foreground are not handled by the SDK.
See Message types for details.
Related
After calling deleteToken() android not receiving any notification. but iOS app still receiving.
Any other way to avoid receiving notification when user opt-out (from app itself), and allow to receive notification after opt-in ?
Note: not using topic concept
in my flutter project, I used FCM to push notifications and flutter_local_notification to display the received notifications
and I used the "data" payload to read the notification in my app.
and it works fine, but when I send more than one notification only the last one appears in the device tray (For both ios & android).
it seems like the application received only one notification
anything to do so multi notifications could be shown in the tray
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
Android - Huawei with HMS push plugin, HmsPushEvent.onRemoteMessageReceived this event was not triggered when app is in killed state. This event only getting called while app is in foreground and background state. Can you please tell which event will be called when app is in killed state.
Push Kit supports two types of messages: notification messages and data messages. After a device receives a data message, the device transfers it to your app instead of directly displaying the message. Your app then parses the message and triggers the corresponding action. Push Kit only functions as a channel, and the delivery of data messages depends on the resident status of your app. However, notification messages can still be delivered even if your app is not launched.
For the sake of saving power and not disturbing users, your app will not be launched by Push Kit after being stopped, and no data messages can be delivered to your app. In this case, you can determine whether to use notification messages based on your services.
To allow users to open a specified page of your app after they tap a notification message, proceed as follows:
Generate Intent parameters
Set intent in the message body on your app server
Register the Activity class to be started in the AndroidManifest.xml file of the app
Receive data in the customized Activity class
From: https://stackoverflow.com/a/64100678/14006527
Alternatively, you can set high-priority data messages to forcibly launch your stopped app to receive and process the messages. To do so, you need to apply for special permission by referring to the related description in FAQs.
I am following the FCM from https://pub.dev/packages/firebase_messaging
and if I am in app or I press home button and do not close app completely , the messages will be sent and every thing is good , but if I close the app completely , the messages will not be send .
what do I should doing ?
There are 2 types of FCM messages:
Notification messages
Data messages
Nofitification messages can be handled when app is terminated, but you have to add backgroundMessageHandler and also register a plugin. Follow guide on plugin docs to do this properly.
Data messages, when app is terminated and on Android are unfortunately not handled by the plugin and the message is lost. On iOS messages are stored and delivered when app comes back to foreground. The source.