我在我的本机应用程序中使用react-native-push-notification来接收远程推送通知。一切正常,当应用程序处于前台或后台时,我会收到所有通知。
但我希望仅在应用程序在后台显示通知。 如果应用位于前台,则不应显示通知。
任何帮助将不胜感激。
我的清单文件包含以下代码:
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_launcher" />
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name" android:value="YOUR NOTIFICATION CHANNEL NAME"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description" android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>
<!-- Change the resource name to your App's accent color - or any other color you want -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color" android:resource="@android:color/white"/>
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
答案 0 :(得分:0)
如果要在后台进行通知,则应仅从服务器发送数据有效载荷消息。如果通知有效载荷包含通知密钥,则android os会自动显示这些通知。因此,最好在通知内容中仅使用数据有效载荷。
请参阅以下有关fcm消息的链接: https://firebase.google.com/docs/cloud-messaging/concept-options