小米设备锁屏未显示推送通知
我曾尝试在通知构建器和通道中使用VISIBILITY_PUBLIC,但它不起作用。
问题是,小米设备在应用程序通知设置中有特殊权限,允许在锁定屏幕时显示通知。但默认情况下,此权限处于关闭状态。但是在一些像"Telegram“这样的应用中,从google play安装后,这个权限默认是打开的,我找不到解决方案如何做到这一点。

发布于 2021-03-12 01:03:00
不知道这是否有帮助,但我在华为设备上遇到了类似的问题(API 29)。我想在我的NotificationChannel上使用NotificationManager.IMPORTANCE_LOW,但当我试图在这台华为设备上发送通知时,它们在锁屏上看不到。
我发现在这台华为设备上有一个App Notification选项,可以使用“温和通知”。这些通知不会显示在锁定屏幕上,如果您的频道使用IMPORTANCE_LOW或更低版本,则默认情况下此选项处于打开状态。将频道的重要性改为IMPORTANCE_DEFAULT解决了我的问题。
因为我想要IMPORTANCE_LOW,因为我不想要Notification Sound,所以我只需要做一些变通工作,并设置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);https://stackoverflow.com/questions/56220629
复制相似问题