react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

No pop up Notification on Remote Notifications

Open s-z-s opened this issue 6 years ago • 29 comments

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?

s-z-s avatar Apr 30 '20 15:04 s-z-s

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 avatar Apr 30 '20 15:04 Dallas62

@Dallas62 doesn't the app handle all incoming notifications in the same way? Do remote notifications give pop ups on your phone?

s-z-s avatar Apr 30 '20 15:04 s-z-s

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 avatar Apr 30 '20 16:04 Dallas62

@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.

s-z-s avatar Apr 30 '20 16:04 s-z-s

Shouldn't the test message from firebase console be delivered with a pop up notification by default @Dallas62 ?

s-z-s avatar Apr 30 '20 16:04 s-z-s

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 avatar May 01 '20 03:05 wbercx

@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?

s-z-s avatar May 01 '20 05:05 s-z-s

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 avatar May 01 '20 07:05 Dallas62

@Dallas62 thanks for the quick update. Local notifications are working fine now. But still the problem persists for remote notifications.

s-z-s avatar May 01 '20 08:05 s-z-s

Did you test with a fresh install?

Dallas62 avatar May 01 '20 08:05 Dallas62

I did the following steps:

  1. react-native unlink
  2. yarn remove
  3. delete node_modules and build folders
  4. yarn install
  5. yarn add
  6. react native link

s-z-s avatar May 01 '20 08:05 s-z-s

@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"/>

cladjules avatar May 05 '20 01:05 cladjules

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.

Dallas62 avatar May 05 '20 05:05 Dallas62

@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.

s-z-s avatar May 05 '20 06:05 s-z-s

Glad it worked, maybe, it would be worth adding that to the documentation? :)

cladjules avatar May 05 '20 08:05 cladjules

I will allow both comportement soon to avoid to restrict the choice (had issue in both cases ...)

Dallas62 avatar May 05 '20 08:05 Dallas62

@Dallas62 are you recommending not to use the solution by @cladjules ?

s-z-s avatar May 05 '20 08:05 s-z-s

Hi @s-z-s You can use this solution, I think it’s a good way to choose the right default channel

Dallas62 avatar May 05 '20 09:05 Dallas62

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.

s-z-s avatar May 05 '20 09:05 s-z-s

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.

s-z-s avatar May 05 '20 10:05 s-z-s