Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter FCM Push Notification Not Working when app is in foreground

I am sending push notifications using Flutter's firebase_messaging package and I send them in the firebase console. When the app is in the background or when it is closed, I am receiving the notifications, however, when the app is in the foreground it is not working. Please tell me if I need to integrate Javascript to make this feature work, and please reference a resource that I can use in order to figure out how I can integrate Javascript with fcm as I haven't found a way to do this with flutter.

like image 943
Coder Avatar asked Aug 04 '18 03:08

Coder


People also ask

How do you run foreground services in flutter?

Open the AndroidManifest. xml file and specify it between the <manifest> and <application> tags. And we need to add this permission to automatically resume foreground service at boot time. And specify the service inside the <application> tag as follows.

How do I trigger push notifications on flutter?

To send a notification, go to Firebase Console → Cloud Messaging and click on Send your first message. Then enter the Title and body field. If you wish to send it to a particular device then click on Send test message and enter the FCM registration token. (Enter the current FCM registration token).

What is foreground push?

Foreground push provides the ability to send regular visible push notifications to the foreground of a user's device. Background push is available regardless of whether a particular device has opted-in to receive push notifications from that brand.

What is difference between APNs and FCM?

APNs needs to be used for push messaging when an application is in the background. Hence, FCM uses APNs to deliver messages when the message contains user visible payload, e.g., body, sound etc. FCM also delivers via APNs when content available is set.


1 Answers

I figured out that someone can use the flutter local notifications plugin so that when the push notification is sent and the app is on the foreground, normally no notification would be delivered to the system tray, but using the flutter local notifications plugin, it would be possible to send a local notification when the app is on the foreground.

like image 183
Coder Avatar answered Sep 27 '22 19:09

Coder