【问题标题】:Show notifications on lock screen of Xiaomi devices在小米设备的锁定屏幕上显示通知
【发布时间】:2019-05-20 12:01:43
【问题描述】:

小米设备的锁屏界面不显示推送通知。

我尝试在通知生成器和频道中使用 VISIBILITY_PUBLIC,但它不起作用。

问题是小米设备在应用通知设置中有特殊权限,允许在锁定屏幕上显示通知。但是这个权限默认是关闭的。但是在某些应用程序中,例如“Telegram”,在从 google play 安装后默认启用此权限,我找不到解决方案。

【问题讨论】:

  • 你找到解决办法了吗?
  • 这里也一样!有什么解决办法吗?

标签: java android kotlin push-notification firebase-cloud-messaging


【解决方案1】:

不确定这是否有帮助,但我在华为设备 (API 29) 上遇到了类似的问题。 我想在我的 NotificationChannel 上使用 NotificationManager.IMPORTANCE_LOW,但是当我尝试在此华为设备上发送通知时,它们在锁定屏幕上不可见。

我发现这台华为设备上有一个应用通知选项可以使用“温和通知”。这些通知不会显示在锁定屏幕上,如果您的频道使用 IMPORTANCE_LOW 或更低,则默认情况下会打开此选项。 将频道的重要性更改为 IMPORTANCE_DEFAULT 正在解决我的问题。

因为我不想要通知声音而想要 IMPORTANCE_LOW,所以我只需要做一些变通方法并设置 setSound(null, null) 和 setVibrationPattern(null)。

NotificationChannel nChannel1 = new NotificationChannel(CHANNEL_1_ID, "Channel Name", NotificationManager.IMPORTANCE_DEFAULT);
nChannel1.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
nChannel1.setSound(null, null);
nChannel1.setVibrationPattern(null);
nChannel1.setDescription("Description");
nManager = context.getSystemService(NotificationManager.class);
nManager.createNotificationChannel(nChannel1);
    
Notification notification = new NotificationCompat.Builder(applicationContext, CHANNEL_1_ID)
            .setContentTitle("title")
            .setContentText("text")
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .build();
nManager.notify(1, notification);

【讨论】:

    猜你喜欢
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    相关资源
    最近更新 更多