[英]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.