客户端
//DCloud-PushSound 在线推送自定义声音
export function initPushSound() {
plugin.setCustomPushChannel({
soundName: "pushsoundhw",
channelId: "huawei_channel",
channelDesc: "报警铃声",
enableLights: true,
enableVibration: true,
importance: 3,
lockscreenVisibility: 0
}, (msg) => {
console.log("push sound error :" msg)
});
}
//华为离线客户端自定义声音配置
export function initHWPushSound() {
const channelManager = getChannelManager()
channelManager.setPushChannel({
channelId: 'huawei_channel',
channelDesc: '华为离线推送',
soundName: 'pushsoundhw' // pushsound.mp3 放在 raw 目录
})
}
//服务端
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": 'huawei_channel',
"/message/android/notification/sound": "pushsoundhw",
"channelId": "huawei_channel",
"sound": "pushsoundhw",
}
}
})
声音文件在 /nativeResources/android/res/raw/pushsoundhw.mp3
代码上有问题吗?
1 个回复
Ask小助手 - Ask社区AI助手
根据知识库中关于华为推送自定义声音的相关内容,结合你提供的代码,在线推送自定义声音未生效的问题可能由以下几个原因导致:
✅ 1. 声音文件命名与路径
pushsoundhw.mp3应命名为pushsoundhw。/nativeResources/android/res/raw/目录下,且需重新打包生效。✅ 2. 通知渠道(channelId)不可复用
建议:
✅ 3. 服务端参数结构问题
你服务端配置中
options.HW的字段写法存在冗余与错误字段:根据知识库,华为推送服务端应使用字段:
✅ 4. 确认离线推送是否已集成成功
请确认:
agconnect-services.json已上传;✅ 5. 建议测试流程
channelId为新的值(如huawei_channel_v2);pushsoundhw,无后缀,放在/res/raw/;✅ 总结
如仍有问题,建议通过 插件市场自定义铃声插件 提供的 demo 进行对比测试。
要回复问题请先登录或注册
公告
更多>相关问题