android - 离子推送通知自定义声音无法在 Android Oreo 及更高版本上播放
问题描述
根据推送插件的 Ionic 文档,我为 android O 及以上版本创建了 Channel。参考链接:-
https://ionicframework.com/docs/native/push/
我实际上想在收到推送通知时播放自定义声音,并且它已经在 Android 7(Nougat)及以下版本上运行,但我在 Android Oreo 及以上版本上遇到问题,正在接收推送通知,但没有播放自定义声音。我参考了很多链接来解决这个问题,但没有任何效果。
参考链接:-
https://github.com/phonegap/phonegap-plugin-push/issues/2017
https://github.com/phonegap/phonegap-plugin-push/issues/2446
在大多数建议的解决方案中,他们建议在 createChannel 方法中添加“声音”参数,如下所示:-
this.push.createChannel({
id: "testchannel7",
description: "asdf",
sound: 'pulse',
// The importance property goes from 1 = Lowest, 2 = Low, 3 = Normal, 4 = High and 5 = Highest.
importance: 4,
vibration: true
}).then(() => console.log('Channel created'));
但我越来越
打字稿错误: - 打字稿错误参数类型'{ id:string; 描述:字符串;重要性:3;声音:字符串;}' 不可分配给“Channel”类型的参数。对象字面量只能指定已知属性,并且“声音”不存在于“通道”类型中。
即使我将 sound.mp3 文件存储在以下位置:-platforms/android/app/src/main/res/raw
在我的有效载荷中,声音参数已经添加,没有扩展名,例如:-
{
...,
...,
sound: soundname,
...
}
我的离子环境配置:-
离子:
离子(离子 CLI) :4.5.0(/usr/local/lib/node_modules/ionic)
离子框架 :离子角 3.9.2
@ionic/app-scripts:3.1.6
科尔多瓦:
科尔多瓦(科尔多瓦 CLI):8.1.2(科尔多瓦-lib@8.1.1)
Cordova 平台 :安卓 7.1.4
Cordova 插件 :cordova-plugin-ionic-webview 3.1.1
推送插件版本:-
phonegap-plugin-push 2.2.3 “PushPlugin”
请帮我解决这个问题,在此先感谢。
解决方案
我和你有同样的问题,并将@ionic-native/push 更新为 4.20.0
npm install --save @ionic-native/push@4.20.0
为我工作。
希望这对你有帮助
推荐阅读
- python - 我可以在创建后或将数据框导出到 sql 表期间在 sql 表中添加主键约束吗
- reactjs - React JS Jest Unit Testing Enzyme Set state for testing
- aws-lambda - 是否可以在 AWS Lambda 上使用 Pytorch?
- angular - 如何将 httpService 返回的字典反序列化为 Angular Map?
- graphql - 我们应该在 Apollo Client 的情况下添加后端 graphql 模式吗?
- f# - 我可以在 F# 中使用可以访问类型本身的方法来扩充所有 DU 类型吗?
- c - GlobalAlloc(GMEM_ZEROINIT|GMEM_FIXED, 0) 会发生什么
- ios - 调用时未在地图视图上显示注释
- gnuplot - 对于具有大量数据的小图,gnuplot 中的线条样式变得不清楚
- r - 使用纬度和经度确定一条线的中间