android - Firebase 自定义通知声音未播放
问题描述
我正在使用 Firebase Cloud Messaging,使用 react-native-push-notification 将通知从 mongoDB 发送到 react-native 应用程序。
通知正在工作,但我无法播放我在 /res/raw 文件夹中的 android 应用程序中添加的自定义通知。
我的代码:
const message = {
"to": userFinded.deviceToken,
"notification": {
"title": 'Body test',
"color": '#ff9d00',
"sound": 'my_sound', //Not working
},
};
我还尝试遵循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';
有时通知声音是默认的,有时我没有任何声音。
请问有什么帮助吗?
解决方案
推荐阅读
- git - 在给定提交上按创建日期列出所有标签
- python - 处理文本数据并转换成 cvc/excel 格式
- sql - 基于累积值的排名
- php - Laravel Controller 加载另一个控制器方法 :: Strange Logic Error
- python - 返回包含算术平均值和无偏样本方差的元组
- r - 在 R 中水平合并数据框 - 文本挖掘
- reactjs - package.json 文件中的调试是什么?
- ios - 如何根据用户输入在表格视图中快速创建动态部分?
- c++ - UAudioComponent 反复播放声音
- javascript - 如何在 React 的同一组件中使用按钮 setState() 另一个输入值?