更新记录

1.0.1(2026-07-15)

修复与优化

  • 优化 Web 端通知弹层位置、进入/退出动画和多通知堆叠策略。
  • 增强 Android 定时/重复通知:支持后台触发、自重排、精确定时、后续文案更新和声音/震动恢复。
  • 优化 Android 通知提醒配置:声音、震动、静默和高优先级场景自动派生渠道,降低旧渠道配置不生效的问题。
  • 同步 iOS、HarmonyOS、Web 对 Android 通知参数的接口承接,补齐 iconPathshowWhencolorexact 等字段的降级处理。
  • 新增 Android 消息横幅验证示例,并同步 uni-app / uni-app x 示例入口。
  • 同步 Android 权限与示例配置,补充 POST_NOTIFICATIONSSCHEDULE_EXACT_ALARMWAKE_LOCK 等后台提醒相关声明。

1.0.0(2026-07-01)

新增

  • 跨平台通知栏 UTS 插件:Android、iOS、HarmonyOS 三端统一公开 API。
  • 通知权限申请、普通/大文本/大图/进度通知,以及更新、完成、取消。
  • 点击回调(onNotificationClick)、打开指定页面、定时/重复通知、通知分组。
  • 动作按钮、静默通知、自动消失、自定义声音与震动节奏等样式参数。
  • Android 动作按钮兼容 UTSArray 桥接解析,带动作按钮的通知自动使用展开样式。
  • Android 声音/震动按 soundPathvibratePatternsilent 自动派生渠道,发送后主动提醒兜底。
  • Android、iOS、HarmonyOS 原生实现与 UTS 类型定义。
  • uni-app / uni-app x 双端示例页(含分组、样式、点击等 11 个场景)与使用文档(三端能力矩阵、自定义基座说明)。

平台兼容性

uni-app(5.06)

Vue2 Vue2插件版本 Vue3 Vue3插件版本 Chrome Chrome插件版本 Safari Safari插件版本 app-vue app-vue插件版本 app-nvue app-nvue插件版本 Android iOS 鸿蒙
1.0.0 1.0.0 1.0.1 1.0.1 1.0.0 1.0.0 5.0 12
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 小红书小程序 快应用-华为 快应用-联盟
- - - - - - - - - - - -

uni-app x(5.06)

Chrome Chrome插件版本 Safari Safari插件版本 Android iOS 鸿蒙 微信小程序
1.0.1 1.0.1 5.0 12 -

xview-notification

跨平台通知栏提示 UTS 插件,Android、iOS、HarmonyOS 使用系统通知能力,Web 使用当前页面 DOM 弹层;四端保持同一套公开 API,支持普通通知、大文本通知、进度通知、点击回调、定时/重复通知、大图通知、通知分组、通知更新和取消。不同系统的通知能力不完全一致,部分能力会在 iOS、HarmonyOS 或 Web 上按平台规则降级。

权限

Android 已在 AndroidManifest 中声明:

  • android.permission.POST_NOTIFICATIONS
  • android.permission.VIBRATE
  • android.permission.SCHEDULE_EXACT_ALARM
  • android.permission.WAKE_LOCK

使用示例

import {
  requestNotificationPermission,
  sendSimpleNotification,
  sendNotification,
  sendProgressNotification,
  scheduleNotification,
  sendRepeatingNotification,
  isExactAlarmEnabled,
  onNotificationClick,
  updateScheduledNotification,
  updateProgress,
  completeProgress,
  cancelAllNotifications
} from '@/uni_modules/xview-notification'

onNotificationClick((event) => {
  console.log('notification click', event.id, event.type, event.target, event.actionId)
  // open-page 需在 App 层自行跳转,插件内不调用 uni.navigateTo
  if (event.type === 'open-page' && event.target) {
    uni.navigateTo({ url: event.target })
  }
})

requestNotificationPermission(
  () => {
    const id = sendSimpleNotification('标题', '通知内容')
    console.log('notification id', id)
  },
  () => {
    console.log('通知权限未开启')
  }
)

const bigId = sendNotification({
  channelId: 'xview_big_text',
  channelName: '大文本通知',
  title: '任务完成',
  content: '展开查看详情',
  bigText: '这里是更长的通知内容。',
  priority: 'high',
  vibrate: true
})

const progressId = sendProgressNotification('处理中', '当前进度 10%', 10, 100)
updateProgress(progressId, 60, 100)
completeProgress(progressId)

scheduleNotification({
  title: '定时提醒',
  content: '5 秒后触发',
  delay: 5000
})

const repeatId = sendRepeatingNotification({
  title: '重复提醒',
  content: '每分钟触发一次',
  repeatInterval: 60 * 1000
})
updateScheduledNotification(repeatId, {
  title: '重复提醒已更新',
  content: '后续触发使用新的标题和正文'
})

if (!isExactAlarmEnabled()) {
  console.log('请在系统设置中手动开启闹钟和提醒权限')
}

scheduleNotification({
  title: '后台准时提醒',
  content: 'Android 12+ 需先开启闹钟和提醒权限',
  delay: 10 * 1000,
  exact: true,
  soundPath: 'default',
  vibrate: true
})

cancelAllNotifications()

大图标与固定 ID

sendSimpleNotification('标题', '带大图标的通知', '/static/logo.png')

sendNotification({
  id: 9001,
  title: '固定 ID 通知',
  content: '再次发送会覆盖同 ID 通知',
  iconPath: '/static/logo.png'
})

cancelNotification(9001)

样式与行为参数

sendNotification({
  title: '样式示例',
  content: '副标题 + 强调色 + 仅提醒一次',
  subText: '业务分类',
  bigTitle: '展开后的大标题',
  color: 0xff0ea5e9,
  showWhen: true,
  onlyAlertOnce: true,
  priority: 'high',
  ongoing: true,
  autoCancel: false
})

sendNotification({
  title: '静默通知',
  content: '不响铃、不震动',
  silent: true
})

sendNotification({
  title: '自动消失',
  content: '5 秒后自动取消',
  timeoutAfter: 5000
})

sendNotification({
  title: '默认提示音',
  content: '使用系统默认通知提示音',
  soundPath: 'default'
})

sendNotification({
  title: '自定义震动',
  content: 'Android 支持自定义震动节奏',
  vibrate: true,
  vibratePattern: [0, 180, 80, 260, 80, 360]
})

Android 消息横幅通知

scheduleNotification({
  channelId: 'xview_heads_up_message',
  channelName: '消息横幅通知',
  title: '开发资料群',
  content: '[1条] 码小趣:后台横幅通知测试',
  priority: 'high',
  soundPath: 'default',
  vibrate: true,
  type: 'open-page',
  target: '/pages/demo/open-page',
  autoCancel: true,
  delay: 5000,
  exact: true
})

验证桌面或其他 App 上方横幅时,不要点击后再切后台。应先安排 5 秒后发送,然后立即按 Home 或切到其他 App,让系统在后台触发通知发布。

Android 顶部横幅由系统通知渠道、通知权限、声音/震动、勿扰模式和厂商 ROM 策略共同决定。本插件在 Android 8.0+ 会将 priority: 'high'priority: 'max' 的非静默通知创建为高重要性渠道,并为 xview_heads_up_message 场景设置消息通知类别;但用户关闭 App 通知、关闭该渠道横幅、进入勿扰模式或厂商系统限制后台提醒时,系统仍可能只进入通知栏或不展示横幅。

如果某个 channelId 已经在设备上被创建为普通重要性,Android 不允许应用静默改高。调试时请更换新的 channelId、清除应用数据、卸载重装,或进入系统通知设置手动打开该渠道的横幅/悬浮通知。

点击行为 type

// 仅拉起应用(默认)
sendNotification({ title: '打开应用', content: '点击后回到前台', type: 'open-app' })

// 拉起应用并跳转页面,target 为页面路径
sendNotification({
  title: '打开页面',
  content: '点击后跳转到业务页',
  type: 'open-page',
  target: '/pages/index/index'
})

// 点击后通过 onNotificationClick 回调 target 字符串
sendNotification({
  title: '点击回调',
  content: '在 callback 中处理业务逻辑',
  type: 'open-callback',
  target: 'order:10086'
})

// 动作按钮会通过 onNotificationClick 回传 actionId
sendNotification({
  title: '订单待处理',
  content: '在通知上直接处理',
  type: 'open-callback',
  target: 'order:10086',
  actions: [
    { id: 'view', title: '查看', type: 'open-page', target: '/pages/demo/open-page' },
    { id: 'confirm', title: '确认', type: 'open-callback', target: 'order:10086:confirm' }
  ]
})

不确定进度

const id = sendProgressNotification('同步中', '正在处理...', 0, 100, true)
updateProgress(id, 50, 100)
completeProgress(id)

定时 triggerAt 与 repeatType

// 指定绝对触发时间(毫秒时间戳)
scheduleNotification({
  title: '预约提醒',
  content: '在指定时间点触发',
  triggerAt: Date.now() + 10 * 1000
})

// 使用 repeatType 快捷周期(minute/hour/day/week)
sendRepeatingNotification({
  title: '每小时提醒',
  content: 'repeatType 示例',
  delay: 3000,
  repeatType: 'hour'
})

cancelScheduledNotification(scheduledId)

updateNotification

updateNotification(progressId, {
  title: '下载完成',
  content: '文件已保存',
  bigText: '点击查看详情',
  progressCurrent: 100,
  progressMax: 100
})

updateScheduledNotification

const repeatId = sendRepeatingNotification({
  title: '库存提醒',
  content: '库存状态待刷新',
  delay: 3000,
  repeatInterval: 60 * 1000
})

updateScheduledNotification(repeatId, {
  title: '库存提醒已更新',
  content: 'A 商品库存低于安全线'
})

示例工程

框架 首页 示例目录
uni-app pages/index/index.vue pages/notification/*.vue
uni-app x pagesx/index/index.uvue pagesx/notification/*.uvue

多端能力对齐

能力 Android iOS HarmonyOS Web
公开 API 完整对齐 完整对齐 完整对齐 DOM 弹层对齐
普通通知 NotificationCompat 原生通知 UserNotifications 本地通知 notificationManager 基础文本通知 当前页面 DOM 弹层
消息横幅 高重要性渠道 + 消息类别,是否弹出由系统和渠道设置决定 按 iOS 系统横幅设置展示 按系统能力降级 当前页面 DOM 弹层
声音/震动 支持 soundPathvibratevibratePattern,并按渠道配置自动派生实际 channel 支持系统通知声音或 bundle 声音;震动遵循 iOS 通知声音/系统设置策略 参数保留,基础通知发布时由系统槽位和用户设置决定 参数保留,不主动播放
静默通知 支持,且不会主动播放声音或震动 支持,不设置通知声音 参数保留,按 HarmonyOS 系统能力降级 DOM 弹层仍显示
进度通知 系统进度条 正文文本进度 正文文本进度 DOM 进度条
大文本 原生大文本样式 正文展开文本 正文文本降级 DOM 展开文本
大图 原生大图样式 通知附件 正文提示图片路径 DOM 图片
分组 原生分组和摘要 threadIdentifier 分组 字段保留,基础文本降级 字段保留,逐条弹出
动作按钮 原生动作按钮,点击回传 actionId 原生动作按钮,点击回传 actionId 动作标题降级到正文展示 DOM 按钮回传 actionId
点击事件 支持 onNotificationClick 支持 onNotificationClick API 保留,当前不产生系统点击 payload DOM 点击回调
定时通知 AlarmManagerexact: true 使用 setAlarmClock UNTimeIntervalNotificationTrigger 进程内 timer 降级 页面内 timer 降级
重复通知 到点后自重排,exact: true 沿用 setAlarmClock 策略 支持,系统要求最小 60 秒 进程内 timer 降级 页面内 timer 降级
更新后续定时文案 支持按任务 ID 持久化更新 title/content 支持内存内 pending request 更新 进程内 timer 降级 页面内 timer 降级
精确定时权限 Android 12+ 需“闹钟和提醒”授权 无独立权限,返回可用 不支持,返回 false 不支持,返回 false

HarmonyOS 当前实现以 API 对齐和基础文本通知为主,动作按钮、分组样式、大图、点击 payload、定时/重复通知均按系统能力降级;需要强交互通知时优先以 Android/iOS 真机能力为准。

API

方法 说明 Android iOS HarmonyOS Web
requestNotificationPermission(success, fail) 申请通知权限 支持 支持 支持 返回弹层可用
isNotificationEnabled() 检查应用通知是否可用 支持 支持 支持 支持
openNotificationSettings() 打开应用通知设置页 支持 支持 支持(应用详情页) 空实现
isExactAlarmEnabled() 检查 Android 精确定时权限 支持 返回 true 返回 false 返回 false
sendNotification(options) 发送通知,返回通知 ID,失败返回 -1 支持 支持 基础文本通知 DOM 弹层
sendSimpleNotification(title, content, iconPath?) 发送普通通知 支持,iconPath 作为大图标 支持,iconPath 作为通知附件兜底 支持,iconPath 降级为正文图片路径 DOM 弹层,iconPath 作为左侧图标
sendProgressNotification(title, content, current, total, indeterminate?) 发送进度通知 支持 文本进度 文本进度 DOM 进度条
onNotificationClick(callback) 监听通知点击事件 支持 支持 API 保留,当前不触发 支持
offNotificationClick() 移除通知点击监听 支持 支持 支持 支持
scheduleNotification(options) 定时通知 支持 支持 进程内 timer 降级 页面内 timer
sendRepeatingNotification(options) 重复通知 支持 支持(最小 60 秒) 进程内 timer 降级 页面内 timer
cancelScheduledNotification(id) 取消定时或重复通知 支持 支持 支持 支持
updateScheduledNotification(id, options) 更新后续定时/重复通知标题和正文 支持 支持 pending request 进程内 timer 降级 页面内 timer
updateNotification(id, options) 更新标题、内容、进度或大文本 支持 支持 支持 支持
updateProgress(id, current, total?) 更新进度通知 支持 支持 支持 支持
completeProgress(id) 将进度通知置为完成 支持 支持 支持 支持
cancelNotification(id) 取消指定通知 支持 支持 支持 支持
cancelAllNotifications() 取消全部通知 支持 支持 支持 支持

options

字段 类型 默认值 说明
channelId string xview_default Android 通知渠道 ID;iOS/HarmonyOS 保留字段
channelName string Xview 通知 Android 通知渠道名称;HarmonyOS 可作为附加文本兜底
title string 必填 通知标题
content string 必填 通知内容
iconPath string - 通知大图标/头像本地路径;Android 作为大图标使用,小图标仍使用应用图标;iOS 作为通知附件兜底;HarmonyOS/Web 按平台能力降级展示
type open-app/open-page/open-callback open-app 点击行为
target string - 页面路径或回调携带数据
id number 随机 通知 ID,相同 ID 会覆盖
color number - 强调色,如 0xff0ea5e9,Android 支持
subText string - 副标题
showWhen boolean true 是否显示时间,Android 支持
priority min/low/default/high/max default 通知优先级,Android 支持完整优先级;Android 8.0+ 中 high/max 非静默通知会创建高重要性渠道以支持横幅展示
ongoing boolean false 是否常驻,Android/HarmonyOS 支持
autoCancel boolean true 点击后是否自动取消,Android/HarmonyOS 支持
onlyAlertOnce boolean true 相同内容是否只提醒一次,Android 生效;iOS/HarmonyOS 保留字段并按系统能力降级;Android 重复通知在未显式设置时会允许每次提醒
vibrate boolean false 是否震动,Android 支持;iOS/HarmonyOS 受系统通知策略影响
vibratePattern number[] - 自定义震动节奏,Android 支持
silent boolean false 静默通知,不主动响铃或震动
timeoutAfter number - 自动消失时间,单位毫秒
soundPath string - default 使用系统默认通知音;Android 支持文件路径或 raw 资源名,iOS 支持 bundle 声音名
actions { id, title, type?, target? }[] - Android/iOS 为通知动作按钮并回传 actionId;HarmonyOS 降级为正文提示。Android/iOS 通常需要展开通知后才显示按钮
showProgress boolean false 是否显示进度,Android 为系统进度条,iOS/HarmonyOS 为正文文本
progress { current, total, indeterminate? } - 进度配置
bigText string - 大文本展开内容,HarmonyOS 降级为正文
bigTitle string - 大文本样式标题,Android/iOS 使用更完整
summaryText string - 摘要说明
bigImagePath string - 大图通知图片路径,Android/iOS 支持,HarmonyOS 降级为正文路径
groupId string - 通知分组 ID,Android/iOS 支持,HarmonyOS 保留字段
groupTitle string - 分组摘要标题,Android/iOS 支持
groupSummary string - 分组摘要内容,Android/iOS 支持,HarmonyOS 可作为正文
isGroupSummary boolean false 是否为分组摘要通知,Android/iOS 支持
delay number 1000 定时通知延迟毫秒数
triggerAt number - 定时通知触发时间戳,毫秒
repeatType minute/hour/day/week - 重复周期快捷值
repeatInterval number - 自定义重复间隔毫秒
exact boolean false Android 是否要求使用后台准时提醒;Android 使用 setAlarmClock,Android 12+ 未授权时定时 API 返回 -1,其他端按平台能力忽略或降级
webMaxVisible number 2 Web 端 DOM 弹层最多同时显示数量,只保留最近通知;App 原生端忽略

updateScheduledNotification options

字段 类型 默认值 说明
title string - 后续定时/重复通知的新标题
content string - 后续定时/重复通知的新正文

updateScheduledNotification 只更新后续触发文案,不修改 channelId、声音、震动、点击行为、分组、动作按钮或精确定时策略。传入无效 ID、任务已取消、或 title/content 都未传时返回 false

隐私、权限声明

1. 本插件需要申请的系统权限列表:

android.permission.POST_NOTIFICATIONS, android.permission.VIBRATE, android.permission.SCHEDULE_EXACT_ALARM, android.permission.WAKE_LOCK

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率: