[英]Show notifications on lock screen of Xiaomi devices
推送通知未显示在小米设备的锁定屏幕上。
我尝试在通知生成器和频道中使用 VISIBILITY_PUBLIC 但它不起作用。
问题是小米设备在应用通知设置中有特殊权限,允许在锁定屏幕上显示通知。 但是这个权限默认是关闭的。 但是在像“电报”这样的一些应用程序中,从谷歌播放安装后默认情况下这个权限是启用的,我找不到如何做到这一点的解决方案。
不确定这是否有帮助,但我在华为设备(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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.