HarmonyOS 关于notificationManager.publish

通过notificationManager.publish发送通知,状态栏不会像其他系统那样弹出通知内容,也没有显示应用通知图标,只有当状态栏下拉以后,能看到通知。

notificationManager.publish代码如下

// 发起通知
let request: notificationManager.NotificationRequest = {
  id: 1,
  content: {
    notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
    normal: {
      title: '注意!手机银行已经切换到后台',
      text: '手机银行已切换到后台',
      additionalText: '点击重新进入手机银行'
    },
  },
  isFloatingIcon:true,
  notificationSlotType:notificationManager.SlotType.SERVICE_INFORMATION,

}
notificationManager.publish(request, (err) => {
  if (null != err) {
    Logger.error(`EntryAbility => onBackground 发送通知异常:${JSON.stringify(err)}`)
    return
  }
  Logger.debug(`通知发送成功`)
})
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
HarmonyOS
2024-12-23 17:12:52
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

将notificationSlotType改成notificationManager.SlotType.SOCIAL_COMMUNICATION,因为只有SOCIAL_COMMUNICATION类型支持横幅通知,相关规则可参考:

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/notification-slot-V5

另外测试时,注意手机设置里,应用的通知管理中,需要把提醒方式的“横幅通知”勾上,这样才会直接弹出消息。

分享
微博
QQ
微信
回复
2024-12-23 20:33:51
相关问题
HarmonyOS notificationManager问题
894浏览 • 1回复 待解决
HarmonyOS ohpm publish如何加上组织名字
779浏览 • 1回复 待解决
HarmonyOS HAR publish时需要的密码问题
1273浏览 • 1回复 待解决
ohpm publish 组问题,该如何解决?
1152浏览 • 1回复 待解决
ohpm publish 推送har包大小的限制
1407浏览 • 1回复 待解决
HarmonyOS 关于Socket
762浏览 • 1回复 待解决
HarmonyOS 关于手势问题
766浏览 • 1回复 待解决
HarmonyOS 关于openCustomDialog方法
619浏览 • 1回复 待解决
关于HarmonyOS Promise机制
1387浏览 • 1回复 待解决
HarmonyOS 关于屏幕高度
804浏览 • 1回复 待解决
HarmonyOS 关于屏幕高度?
784浏览 • 0回复 待解决
HarmonyOS关于navigation问题
1512浏览 • 1回复 待解决
HarmonyOS 关于crash问题
1376浏览 • 1回复 待解决
HarmonyOS 关于加固问题
788浏览 • 1回复 待解决
HarmonyOS 关于合并对象
675浏览 • 2回复 待解决