简体   繁体   English

React-native-firebase 后台通知(Android)

[英]React-native-firebase notification in background (Android)

I am using the react-native-firebase library and I am brainstorming to customize my notifications when they are in the background, I tried to follow the documentation but to no avail, are there native code.java to handle notifications?我正在使用 react-native-firebase 库,并且我正在集思广益以在后台自定义通知时,我尝试按照文档进行操作,但无济于事,是否有本机 code.java 来处理通知?

To customize the background notifications you can add in the index of your application:要自定义后台通知,您可以在应用程序的索引中添加:

 import { AppRegistry } from 'react-native' import App from './App' import { backgroundMessageNotificationHandler } from 'src/common/notifications' AppRegistry.registerComponent('testApp', () => App) AppRegistry.registerHeadlessTask( 'RNFirebaseBackgroundMessage', () => backgroundMessageNotificationHandler)

The backgroundMessageNotificationHandler could be something like that: backgroundMessageNotificationHandler 可能是这样的:

 export const backgroundMessageNotificationHandler = async (message: any) => { const localNotification = new firebase.notifications.Notification().android.setChannelId(androidNotificationsChannel.channelId).android.setSmallIcon('iconBlackAndWhite').android.setLargeIcon('iconBlackAndWhite').android.setPriority(firebase.notifications.Android.Priority.High).setNotificationId(message.messageId).setSound('default').setTitle(message.data.title).setBody(message.data.body).setData(message.data) if (Platform.OS === 'android') { createChannel() } firebase.notifications().displayNotification(localNotification) return Promise.resolve() }

Remember to follow the steps to setting up the build.gralde, MainActivity and AndroidManifest.请记住按照步骤设置 build.grade、MainActivity 和 AndroidManifest。 You can follow the steps specified in the following post:您可以按照以下帖子中指定的步骤进行操作:

React-Native Android Push Notification via Firebase React-Native Android 通过 Firebase 推送通知

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 react-native-firebase 通知崩溃 - react-native-firebase notification crash 为什么从 firebase 控制台发送的通知能够绕过 android 后台任务限制? - 反应原生火力基地 - - Why notifications sent from firebase console are able to bypass android background task limitation? - react-native-firebase - react-native-firebase-收到推送通知后应用崩溃(Android) - react-native-firebase - App Crash after Push Notification Received (Android) 默认情况下如何使用react-native-firebase启用浮动通知? - How to enabled floating notification by default with react-native-firebase? 当应用程序运行时,react-native-firebase收到通知 - react-native-firebase receiving notification when app in running react-native-firebase自定义声音在android 8,android 9上不起作用 - react-native-firebase Custom sound not working on android 8, android 9 使用 react-native-firebase 时添加对 Android 通知的回复 - Add replies to Android notifications while using react-native-firebase Android发行版上的react-native-firebase NullPointerException - react-native-firebase NullPointerException on android release build 无法在 Android 中设置 @react-native-firebase/messaging - Can't setup @react-native-firebase/messaging in Android android设置中的react-native-firebase依赖问题 - react-native-firebase dependency issue in android setup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM