No pop up Notification on Remote Notifications
In my app, I have setup local as well as remote notifications. The local notifications are working fine and show pop up notifications correctly. But remote notifications donot show as pop up notifications. They are only shown in the notification tray when the notification arrives. Why is it happening that local notifications work fine but remote notifications give such problems?
Hi, This is not the same kind of notifications, the comportement cannot be compared. You might be able to configure this in the sender (server-side).
@Dallas62 doesn't the app handle all incoming notifications in the same way? Do remote notifications give pop ups on your phone?
Remote Notification and Local Notification are not handle the same way, if you want this behaviour, you will have to specify it server-side. Please refer to this documentation: https://firebase.google.com/docs/cloud-messaging/concept-options
@Dallas62 I am sending this data from server side:
{"to":"myFCMtoken","notification":{"title":"Working Good","body":"Notification delivered successfully.","sound":"sampleaudio"},"data":{"type":"order"},"priority":"high"}
In my previous app using react native firebase, this same data used to give pop up notifications.
Shouldn't the test message from firebase console be delivered with a pop up notification by default @Dallas62 ?
This could be a regression. My local notifications display immediately using 3.2.1, but are not displayed using 3.3.0. They do land in the notification tray though.
@wbercx I just noticed the same behavior in mine too. Local notifications used to work fine in 3.2.1. Now in 3.3.0, all notifications are displayed in the tray only. @Dallas62 do you have any idea about this?
Hi, I just release version 3.3.1 I made a mistake by confusing priority and importance between notification and channel, it's now fixed but you might need to clean node_modules and Cie.
@Dallas62 thanks for the quick update. Local notifications are working fine now. But still the problem persists for remote notifications.
Did you test with a fresh install?
I did the following steps:
- react-native unlink
- yarn remove
- delete node_modules and build folders
- yarn install
- yarn add
- react native link
@s-z-s took me some time, but I figured out.
The default channel created by the library is
String channel_id = NOTIFICATION_CHANNEL_ID + "-" + importance + "-" + DEFAULT_VIBRATION;
Importance High and Vibration 300.
Importance is high, it will show the banner by default.
You need to tell Android to use that channel by default, add that to your AndroidManifest:
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="rn-push-notification-channel-id-4-300" />
You can add that after <meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
android:value="HealthForceGo"/>
Hi @cladjules
yes and there is a channel each time you pop a notification with different configuration (sound, vibration, importance).
To avoid a huge refactoring in channel management and break the current interface, this choice have been made.
For proper implementation, I would suggest to help wix/react-native-notifications that bind directly the API of Android which made channel management proper. But it doesn't support Scheduled notification at the moment.
@cladjules this solved the problem! Thanks a lot! @Dallas62 I was going through RNPushNotificationHelper.java and tried to changed default importance for notifications as high from there but didn't work.
Glad it worked, maybe, it would be worth adding that to the documentation? :)
I will allow both comportement soon to avoid to restrict the choice (had issue in both cases ...)
@Dallas62 are you recommending not to use the solution by @cladjules ?
Hi @s-z-s You can use this solution, I think it’s a good way to choose the right default channel
Hi @Dallas62 Thanks, I will use it then. Also, I think these two metas need to be added to the documentation:
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_stat_logo" />
<meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/ic_launcher_background" />
The notification tray was only displaying the app icon as a grey blob. Adding these gave me a custom icon there too.
I just noticed in RNPushNotificationHelper.java that if we put a transparent all white icon named as ic_notification.png in mipmap folder, the icon is used in the notification tray. The above was for remote notifications and this is for local notifications.