我使用react本地firebase库进行推送通知,我为两个不同的通知播放了两个不同的声音,所以我为一个通知播放了一些.mp3声音,为另一个播放了默认声音,所以问题是应用程序只播放第一个通知中的声音,而对于rest通知播放第一个播放的声音,所以我认为问题是通知信息没有更新,这是它为第一个notification.even应用程序获得的所有通知播放相同的声音。我们在通知数据中获得正确的信息,但它没有更新声音。
版本: react-native-firebase:"4.3.8“react-native:"0.56.1”
是的,我正在从firebase获取数据,下面是我的代码,用于设置通知的声音。
this.notificationListener = firebase
.notifications()
.onNotification((notification: Notification) => {
const channel = new firebase.notifications.Android.Channel(
'test-channel',
'Test Channel',
firebase.notifications.Android.Importance.Max
).setDescription('My apps test channel');
if (notification && notification.data) {
const data = notification.data;
if (data && data.messageKey) {
//here I set the sound on basis of notification data to the channel
...
}
}
// Create the channel
firebase.notifications().android.createChannel(channel);
// Process your notification as required
notification
.android.setChannelId('test-channel')
.android.setSmallIcon(Images.logoSmall);
firebase.notifications()
.displayNotification(notification);
});发布于 2019-08-01 15:47:02
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
发布于 2019-02-21 22:23:22
setSound()在API26中被弃用。请改用NotificationChannel.setSound()。
https://stackoverflow.com/questions/54809170
复制相似问题