我正在使用Firebase Cloud Messaging,使用react-native-push-notification将通知从mongoDB发送到react-native应用程序。
通知工作正常,但我无法播放我在/res/raw文件夹中添加的自定义通知。
我的代码:
const message = {
"to": userFinded.deviceToken,
"notification": {
"title": 'Body test',
"color": '#ff9d00',
"sound": 'my_sound', //Not working
},
};
FCM文档
我也尝试遵循documentation of react-native-push-notification并执行以下操作:
PushNotification.localNotification({
/* Android Only Properties */
channelId: 'fcm_fallback_notification_channel', // (required) channelId, if the channel doesn't exist, notification will not trigger.
soundName: 'my_sound.mp3', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
});
PushNotification.createChannel(
{
channelId: 'fcm_fallback_notification_channel', // (required)
channelName: 'My channel', // (required)
soundName: 'my_sound.mp3', // (optional) See `soundName` parameter of `localNotification` function
});
我尝试了不同的版本:
soundName: 'my_sound.mp3';
soundName: 'my_sound';
soundName: 'android.resource://com.xyz/raw/my_sound';
soundName: 'android.resource://com.seeed/raw/my_sound';
有时通知声音是默认的,有时我没有任何声音。
有什么需要帮忙的吗?
1条答案
按热度按时间11dmarpk1#
您还需要发送android_channel_id
就像这样