首页 > 解决方案 > 离子推送通知自定义声音无法在 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”

请帮我解决这个问题,在此先感谢。

标签: androidcordovaionic-frameworkpush-notificationphonegap

解决方案


我和你有同样的问题,并将@ionic-native/push 更新为 4.20.0

npm install --save @ionic-native/push@4.20.0

为我工作。

希望这对你有帮助


推荐阅读