w***@163.com
w***@163.com
  • 发布:2026-02-10 14:03
  • 更新:2026-02-10 14:28
  • 阅读:57

DCloud-PushSound 自定义铃声服务端配置不生效,推送消息还是默认声音

分类:ASK社区

客户端代码
export function initPushSound() {
plugin.setCustomPushChannel({
soundName: "pushsound",
channelId: "alarm_sound",
channelDesc: "报警铃声",
enableLights: true,
enableVibration: true,
importance: 3,
lockscreenVisibility: 0
}, (msg) => {
console.log("push sound error :" msg)
});

}

服务端代码

return await uniPush.sendMessage({
"push_clientid": jsonObj.cid, //客户端推送标识push_clientid
"force_notification": true,
"title": jsonObj.title,
"content": jsonObj.content,
"payload": jsonObj.payload,
"options": {
"HW": {
// 值为int 类型。1 表示华为测试消息,华为每个应用每日可发送该测试消息500条。此 target_user_type 参数请勿发布至线上。
"/message/android/category": "WORK", //华为消息分类,提醒事项(如待办事项)
"/message/android/notification/channel_id": 'alarm_sound',
"/message/android/notification/default_sound": false,
"/message/android/notification/sound": "/raw/pushsound",

        },  

    }  
})
2026-02-10 14:03 负责人:无 分享
已邀请:
Ask小助手

Ask小助手

根据知识库内容,DCloud-PushSound 自定义铃声服务端配置不生效的问题可能由以下原因导致:

  1. 铃声文件未正确放置
    根据文档,Android平台需要将音频文件(如pushsound.mp3)放置在nativeResources/android/res/raw/目录下,且文件名需与soundName参数完全一致(不带后缀)。请确认文件已正确放置并重新打包。

  2. 服务端参数配置问题

    • 华为推送的sound参数应为文件名(如pushsound),而非路径(如/raw/pushsound)。
    • 需确保channel_id与客户端创建的channelIdalarm_sound)完全一致。
  3. 客户端渠道未生效
    客户端需调用setCustomPushChannel创建渠道,且需在打包后生效。若未打包或渠道创建失败,铃声将使用默认设置。

  4. 厂商通道限制
    部分厂商(如华为)可能对自定义铃声有限制,需确认华为开发者后台已配置对应渠道。

验证步骤

  1. 检查nativeResources/android/res/raw/pushsound.mp3是否存在。
  2. 服务端华为参数修改为:
    "/message/android/notification/sound": "pushsound"  
  3. 重新打包应用并测试。

若仍无效,建议通过插件市场确认插件版本是否最新,或检查日志确认渠道创建是否成功。

内容为 AI 生成,仅供参考
w***@163.com

w***@163.com (作者)

客户端
export function initPushSound() {
plugin.setCustomPushChannel({
soundName: "pushsoundhw",
channelId: "alarm_sound",
channelDesc: "报警铃声",
enableLights: true,
enableVibration: true,
importance: 3,
lockscreenVisibility: 0
}, (msg) => {
console.log("push sound error :" + msg)
});

}

服务端

return await uniPush.sendMessage({
"push_clientid": jsonObj.cid, //客户端推送标识push_clientid
"force_notification": true,
"title": jsonObj.title,
"content": jsonObj.content,
"payload": jsonObj.payload,
"options": {
"HW": {
"/message/android/category": "WORK", //华为消息分类,提醒事项(如待办事项)
"/message/android/notification/channel_id": 'alarm_sound',
"/message/android/notification/default_sound": false,
"/message/android/notification/sound": "pushsoundhw",
"channelId": "huawei_channel",
"sound": "pushsoundhw",

        }  

    }  
})  

文件资源放在 nativeResources/android/res/raw/pushsoundhw.mp3

推送后还是没有发出自定义声音什么问题

要回复问题请先登录注册