Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent to display FCM notification on Flutter app background?

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  print('Handling a background message ${message.messageId}');
}
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

I can display background notifications with these snippet codes. But is there any way to not display some specific notification in the background?

For example I don't want to display notifications with data = {title = "call"}

like image 266
saeid Avatar asked Nov 23 '25 11:11

saeid


1 Answers

from the sender device u have to send data only notification

await http.post(
          Uri.parse('https://fcm.googleapis.com/fcm/send'),
          headers: <String, String>{
            'Content-Type': 'application/json; charset=UTF-8',
            'Authorization': 'key=$serverKey',
          },
          body: jsonEncode(
            <String, dynamic>{
              'data': <String, dynamic>{
                'id': '2',
                'status': 'done'
              },
              'to': userToken,
              "collapse_key": uid,
            },
          ),
        );
like image 139
Husen Avatar answered Nov 27 '25 14:11

Husen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!