Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom notification channel for FCM in flutter

I am trying to customize notification sound of firebase_messaging in flutter. On foreground I am implementing flutter_local_notifications package to deliver notification where I have setup custom sound and vibration. But in case of background, notification is handled by default notification channel. Is there any way I can create a notification channel or use the one I just created using flutter_local_notifications package?

like image 613
Zero Live Avatar asked Oct 26 '22 22:10

Zero Live


1 Answers

For those of you arriving here because your FCM messages aren't acting as you prefer while your app is in the background:

You will probably need to create a Notification Channel if you want a "heads-up" notification when the app is in the background and you want to have your own custom sound accompanying it. The default Notification Channel used by the FCM does not have the "pop on screen" setting enabled and uses the default system sound. You can see this by going to the app's settings on your device.

OP is using the flutter_local_notifications package, which is pretty much the "go-to" package for notification handling in flutter. You can create your own Notification Channels via the createNotificationChannel method and assign your desired parameters (including sound and priority level). This is the quick and easier way of getting your notifications to act as you want them.

If you want to create your own Notification Channel without the flutter_local_notifications package, then you will have to modify your MainActivity.kt (or Java) file in its native form. It's not overly complicated, but it is more low-level than just using the flutter_local_notifications package. This Medium post describes how to do that (for Android).

like image 193
J. Saw Avatar answered Nov 15 '22 06:11

J. Saw