You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Notifee通知触发屏幕唤醒(含锁屏场景)?

解决Notifee通知无法唤醒锁屏屏幕的问题

问题说明

使用Notifee推送通知时,期望设备在锁屏状态下收到通知能自动唤醒屏幕,但当前配置下屏幕仍保持休眠,现有配置代码如下:

// Display a notification
await notifee.displayNotification({
  id: 'default',
  title: notification.message?.title,
  body: notification.message?.body,
  android: {
    category: AndroidCategory.CALL,
    vibrationPattern: [300, 500],
    lights: ['red', 300, 600],
    channelId,
    smallIcon: 'ic_launcher', // optional, defaults to 'ic_launcher'.
    importance: AndroidImportance.HIGH,
    visibility: AndroidVisibility.PUBLIC,
    pressAction: {
      id: 'default',
      launchActivity: 'default',
      // launchActivity: 'com.awesome.app.CustomActivity',
    },

    fullScreenAction: {
      id: 'full-screen',
      mainComponent: 'custom-component',
      // For Android Activity other than the default:
      launchActivity: 'com.awesome.app.FullScreenActivity',
    },
    // asForegroundService: true,
    actions: [
      {
        title: 'Answer',
        pressAction: {id: 'answer', launchActivity: 'default'},
      },
      {
        title: 'Cancel',
        pressAction: {
          id: 'decline',
        },
      },
    ],
  },
});

解决方案

要实现锁屏唤醒,需在Android配置中补充关键属性,并确保权限配置正确:

1. 补充通知核心配置

在android配置节点下添加showWhenLocked和turnScreenOn两个属性,直接控制通知触发时的锁屏显示与唤醒逻辑:

android: {
  // 保留原有配置...
  showWhenLocked: true,
  turnScreenOn: true,
  // 保留原有配置...
}

2. 配置Android权限

在项目的AndroidManifest.xml中添加必要权限:

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />

3. 完整修改后的代码示例

// Display a notification
await notifee.displayNotification({
  id: 'default',
  title: notification.message?.title,
  body: notification.message?.body,
  android: {
    category: AndroidCategory.CALL,
    vibrationPattern: [300, 500],
    lights: ['red', 300, 600],
    channelId,
    smallIcon: 'ic_launcher',
    importance: AndroidImportance.HIGH,
    visibility: AndroidVisibility.PUBLIC,
    // 新增唤醒相关配置
    showWhenLocked: true,
    turnScreenOn: true,
    pressAction: {
      id: 'default',
      launchActivity: 'default',
    },

    fullScreenAction: {
      id: 'full-screen',
      mainComponent: 'custom-component',
      launchActivity: 'com.awesome.app.FullScreenActivity',
    },
    actions: [
      {
        title: 'Answer',
        pressAction: {id: 'answer', launchActivity: 'default'},
      },
      {
        title: 'Cancel',
        pressAction: {
          id: 'decline',
        },
      },
    ],
  },
});

关键说明

  • showWhenLocked:允许通知在锁屏状态下直接显示
  • turnScreenOn:触发通知时自动唤醒设备屏幕
  • 配合已设置的category: AndroidCategory.CALL和importance: AndroidImportance.HIGH,确保通知优先级足够高,避免被系统拦截
  • Android 12+设备需USE_FULL_SCREEN_INTENT权限以支持全屏通知唤醒逻辑

内容的提问来源于stack exchange,提问作者Pavel Shilyaev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 09:05:06