首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React-native-firebase后台通知(Android)

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

Stack Overflow用户
提问于 2019-10-10 21:43:49
回答 1查看 1.4K关注 0票数 0

我正在使用react- native -firebase库,当它们在后台时,我正在集思广益地定制我的通知,我试图按照文档操作,但没有用,有没有本机代码.java来处理通知?

EN

回答 1

Stack Overflow用户

发布于 2019-10-10 22:11:51

要自定义后台通知,可以将其添加到应用程序的索引中:

代码语言:javascript
复制
import { AppRegistry } from 'react-native'
import App from './App'
import { backgroundMessageNotificationHandler } from 'src/common/notifications'

AppRegistry.registerComponent('testApp', () => App)
AppRegistry.registerHeadlessTask(
  'RNFirebaseBackgroundMessage',
  () => backgroundMessageNotificationHandler)

backgroundMessageNotificationHandler可能是这样的:

代码语言:javascript
复制
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()
}

请记住按照设置build.gralde、MainActivity和AndroidManifest的步骤进行操作。您可以按照以下帖子中指定的步骤进行操作:

React-Native Android Push Notification via Firebase

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58324413

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档