客户端代码
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",
},
}
})
2 个回复
Ask小助手
根据知识库内容,DCloud-PushSound 自定义铃声服务端配置不生效的问题可能由以下原因导致:
铃声文件未正确放置
根据文档,Android平台需要将音频文件(如
pushsound.mp3)放置在nativeResources/android/res/raw/目录下,且文件名需与soundName参数完全一致(不带后缀)。请确认文件已正确放置并重新打包。服务端参数配置问题
sound参数应为文件名(如pushsound),而非路径(如/raw/pushsound)。channel_id与客户端创建的channelId(alarm_sound)完全一致。客户端渠道未生效
客户端需调用
setCustomPushChannel创建渠道,且需在打包后生效。若未打包或渠道创建失败,铃声将使用默认设置。厂商通道限制
部分厂商(如华为)可能对自定义铃声有限制,需确认华为开发者后台已配置对应渠道。
验证步骤:
nativeResources/android/res/raw/pushsound.mp3是否存在。若仍无效,建议通过插件市场确认插件版本是否最新,或检查日志确认渠道创建是否成功。
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
推送后还是没有发出自定义声音什么问题
要回复问题请先登录或注册
公告
更多>相关问题