React-native-push-notification: Receive notification but not show pop-up in Android

Created on 19 Nov 2018  路  5Comments  路  Source: zo0r/react-native-push-notification

you can try edit file

/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java

find (int importance = NotificationManager.IMPORTANCE_DEFAULT;)

edit (int importance = NotificationManager.IMPORTANCE_HIGH;)

finally send again with :

"to" : "fr7CuLTwzXI:APA91bEw6EaBsvbk9fftCjomX7BpabPCRSczyDs4jY29TF66pwRBNGYA5U9oDS6HBvHu33T8T6hCptHgzO3Rd6qXUdKTuYosnv_PRDuhWauhzwYA3OU_g5pngsscUyOU_K9ZW8BJDhNC",
"time_to_live": 86400,
"collapse_key": "new_message",
"delay_while_idle": false,
"priority":"high",
"content_available":true,
"data": {
"title": "DIP VIETNAM TEST GUI TIN NHAN",
"message": "Noi Dung tin nhan day",
"android_channel_id":"rn-push-notification-channel",
"sound": "default",
"high_priority": "high",
"show_in_foreground": true
}

Stale

Most helpful comment

I spent hours reading Java code and checking the output of adb logcat, when I found these 2 lines:

FirebaseMessaging: Notification Channel requested (default-channel) has not been created by the app. Manifest configuration, or default, value will be used.
FirebaseMessaging: Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.

It took me awhile longer to understand what was going on, but I think I figured it out now. It's all due to this line: https://github.com/zo0r/react-native-push-notification/blob/aaf2d19925db4666d6018c0ab1ff0d7d4c90a21d/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java#L572

It creates a notification channel but the channel ID is hardcoded! I assumed that the com.dieam.reactnativepushnotification.notification_channel_name sets the ID of the channel (in my case I called it "default-channel", but it only sets the display name. This wouldn't be so bad if it were documented somewhere!

Firebase documentation states that apps targeting SDK 26 (Oreo) or higher must set a channel for the notification to appear. Through experimentation I discovered that notification icons will still show in the status bar, but will not display as a "heads-up" notification, which is what people typically expect notifications to do. Downgrading your target SDK version might work here, except that Google Play demands that all new apps target SDK 26 now! So much for that solution.

So there's 2 possible solutions. The messy way is to always make sure you set your channel ID in your push notification. But this might not work if you're going through a third-party service like Amazon's SNS... it all depends on if they let you set the channel ID.

The better solution is to modify your manifest XML like I did above. This should be in the documentation but isn't. I'm going to submit a PR.

My emotions are an equal mix of joy (for finally getting it to work) and hatred. Seriously, if you hardcode things like this and don't document it anywhere, there is a special circle in Hell reserved for you.

All 5 comments

You don't need all this, and you got part of it wrong anyway. The critical piece here is the Android channel ID called rn-push-notification-channel-id (you forgot the -id part).

In your AndroidManifest.xml file, add this line:

<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="rn-push-notification-channel-id" />

You can send the channel in the push payload if you want, but I think my way is easier.

See my next message for how I discovered this.

I spent hours reading Java code and checking the output of adb logcat, when I found these 2 lines:

FirebaseMessaging: Notification Channel requested (default-channel) has not been created by the app. Manifest configuration, or default, value will be used.
FirebaseMessaging: Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.

It took me awhile longer to understand what was going on, but I think I figured it out now. It's all due to this line: https://github.com/zo0r/react-native-push-notification/blob/aaf2d19925db4666d6018c0ab1ff0d7d4c90a21d/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java#L572

It creates a notification channel but the channel ID is hardcoded! I assumed that the com.dieam.reactnativepushnotification.notification_channel_name sets the ID of the channel (in my case I called it "default-channel", but it only sets the display name. This wouldn't be so bad if it were documented somewhere!

Firebase documentation states that apps targeting SDK 26 (Oreo) or higher must set a channel for the notification to appear. Through experimentation I discovered that notification icons will still show in the status bar, but will not display as a "heads-up" notification, which is what people typically expect notifications to do. Downgrading your target SDK version might work here, except that Google Play demands that all new apps target SDK 26 now! So much for that solution.

So there's 2 possible solutions. The messy way is to always make sure you set your channel ID in your push notification. But this might not work if you're going through a third-party service like Amazon's SNS... it all depends on if they let you set the channel ID.

The better solution is to modify your manifest XML like I did above. This should be in the documentation but isn't. I'm going to submit a PR.

My emotions are an equal mix of joy (for finally getting it to work) and hatred. Seriously, if you hardcode things like this and don't document it anywhere, there is a special circle in Hell reserved for you.

@krozett Thanks this helped me!

You need to have the channel name set, description and the channel id as per @krozett

<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name" android:value="XXXXX"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description" android:value="XXXXX"/>
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="rn-push-notification-channel-id" />

@krozett Thanks a lot!

I just add the AndroidManifest.xml like @apski did

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

atteia picture atteia  路  4Comments

GastonEDiaz picture GastonEDiaz  路  3Comments

anativ picture anativ  路  3Comments

uendar picture uendar  路  3Comments

NiuQiaoling picture NiuQiaoling  路  3Comments