我正在使用react native firebase库进行推送通知,我正在为两种不同的通知播放两种不同的声音,所以我为一种通知播放一些.mp3声音,而对于另一种则默认播放,所以问题是应用程序仅在播放那种声音即将在应用程序的第一个通知中出现,而在休息通知中将播放第一个播放的声音,因此我认为问题在于通知信息没有更新,这就是它为第一个通知收到的所有应用程序都播放相同声音的声音。通知数据中包含正确的信息,但不会更新声音。
版本: react-native-firebase:“ 4.3.8” react-native:“ 0.56.1”
是的,我正在从Firebase获取数据,下面是设置声音以进行通知的代码。
Dockerfile
答案 0 :(得分:0)
setSound()
已在API 26中弃用。改为使用NotificationChannel.setSound()
。
答案 1 :(得分:0)
1)在android中,将您的自定义声音文件添加到[project_root] / android / app / src / main / res / raw
2)创建通知频道
const channel = new firebase.notifications.Android.Channel('channel_name', 'channel_name', firebase.notifications.Android.Importance.High)
.setDescription('channel_name')
3)在通知.setSound('default')
中添加声音firebase.notifications().android.createChannel(channel);
const localNotification = new firebase.notifications.Notification({
sound: 'default',
show_in_foreground: true,
})
.setNotificationId(new Date().valueOf().toString())
.setTitle(noti_payload.title)
.setSound('default')
.setBody(noti_payload.message)
.setData({
now: new Date().toISOString(),
payload: noti_payload,
})
.android.setAutoCancel(true)
.android.setBigText(noti_payload.message)
.android.setLargeIcon('ic_launchers')
.android.setVibrate(1000)
.android.setColor('#74c900')
.android.setColorized(true)
.android.setChannelId('channel_name') // e.g. the id you chose above
.android.setSmallIcon('ic_launchers') // create this icon in Android Studio
.android.setPriority(firebase.notifications.Android.Priority.High);
firebase
.notifications()
.displayNotification(localNotification)
重要说明:-
完成上述步骤后,请卸载应用并删除捆绑软件,因为某些时候缓存的捆绑软件资产包含默认声音,并且更改不会反映出来。
每次更改声音时,都需要重新构建捆绑包
请同时检查以下链接 https://rnfirebase.io/docs/v4.0.x/notifications/reference/Notification