HarmonyOS 本地推送没有提示
创建本地推送的时候,没有任何的提示,如何创建才能给用户提示有新消息呢? 创建代码在下方
async pushTest() {
let img = await getContext(this).resourceManager.getMediaContent($r('app.media.nbicon'));
let imageSource:image.ImageSource = image.createImageSource(img.buffer.slice(0));
let decodingOptions : image.DecodingOptions = {
editable: true,
desiredPixelFormat: 3,
}
// 创建pixelMap
let icon: image.PixelMap | undefined = await imageSource.createPixelMap(decodingOptions);
let wantAgentObj: WantAgent; // 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。
// 通过WantAgentInfo的operationType设置动作类型
let wantAgentInfo: wantAgent.WantAgentInfo = {
wants: [
{
deviceId: '',
bundleName: "com.xxx.mybundleName",
abilityName: "EntryAbility",
action: '',
entities: [],
uri: '',
parameters: {
'test1': 'test1',
'test2': 'test2',
'test3': 'test3',
}
}
],
operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.CONSTANT_FLAG]
};
wantAgentObj = await wantAgent.getWantAgent(wantAgentInfo);
icon = undefined
let notificationRequest: notificationManager.NotificationRequest = {
content: {
notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: '测试标题123',
text: '测试内容456',
},
},
wantAgent: wantAgentObj
};
if (icon) {
notificationRequest.smallIcon = icon
notificationRequest.largeIcon = icon
}
notificationManager.publish(notificationRequest, (err: BusinessError) => {
if (err) {
console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info('Succeeded in publishing notification.');
});
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
HarmonyOS
赞
收藏 0
回答 1
相关问题
HarmonyOS 实况窗推送,提示没有权限
693浏览 • 1回复 待解决
HarmonyOS 手机能收到推送消息,但是手机没有任何横幅,声音及震动的提示
814浏览 • 1回复 待解决
HarmonyOS 在console使用推送通知测试推送提示“所有token不合法”
1184浏览 • 1回复 待解决
HarmonyOS 推送时,后台提示"所有Token都不合法
772浏览 • 1回复 待解决
读取本地json 文件提示权限拒绝
4129浏览 • 1回复 待解决
HarmonyOS 推送的铃声支持自己设置吗?测试发现推送没有声音
1027浏览 • 1回复 待解决
HarmonyOS推送服务,有没有广播的方式呢?
1280浏览 • 2回复 待解决
HarmonyOS 消息推送代码怎么写,有没有相关文档
919浏览 • 1回复 待解决
HarmonyOS agc推送通知指定设备,提示‘所有token都不合法’
680浏览 • 1回复 待解决
启动本地模拟器,提示Haxm安装失败
1472浏览 • 1回复 待解决
HarmonyOS DevEco Studio 开发工具,没有代码提示
1361浏览 • 1回复 待解决
HarmonyOS PushKit推送通知消息成功,但是没有铃声或者震动提醒
1141浏览 • 1回复 待解决
启动DevEco Studio本地模拟器,提示无法安装HAXM
10234浏览 • 1回复 待解决
HarmonyOS 已经开启地图服务仍然提示没有权限
1440浏览 • 1回复 待解决
启动DevEco Studio本地模拟器,提示无法安装GVM
9402浏览 • 1回复 待解决
HarmonyOS 使用drawing.canvas绘制本地Image时,提示参数错误
775浏览 • 1回复 待解决
无法测试推送,AGC平台暂不支持发送。有没有其他测试推送的工具
954浏览 • 1回复 待解决
HarmonyOS 在AppGallery connect上进行推送服务测试时,页面提示token不合法
1027浏览 • 0回复 待解决
HarmonyOS 个推推送【研究华为推送】-----换成华为推送
1115浏览 • 1回复 待解决
HarmonyOS 系统推送如何控制推送开关?
938浏览 • 1回复 待解决
HarmonyOS 推送服务限制每日推送条数
1372浏览 • 1回复 待解决
启动DevEco Studio本地模拟器,提示SDK路径已更改
9276浏览 • 1回复 待解决
启动DevEco Studio本地模拟器,提示镜像文件缺失
12594浏览 • 2回复 待解决
启动DevEco Studio本地模拟器,提示VT/NX不可用
8496浏览 • 1回复 待解决
关于元服务的json本地数据操作-需要完整的代码提示
331浏览 • 1回复 已解决
可以指定notificationSlotType
SlotType:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-notificationmanager-V5#slottype
不同类型的通知渠道对应的通知提醒方式不同:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/notification-slot-V5#通知渠道类型说明