小米设备锁屏未显示推送通知。
我已尝试在通知构建器和通知渠道中使用VISIBILITY_PUBLIC,但没有效果。
问题在于小米设备在应用程序通知设置中具有特殊权限,允许在锁屏上显示通知。但是这个权限默认是关闭的。但在一些应用程序(如“Telegram”)中,从Google Play安装后此权限默认是打开的,我无法找到解决方案。
小米设备锁屏未显示推送通知。
我已尝试在通知构建器和通知渠道中使用VISIBILITY_PUBLIC,但没有效果。
问题在于小米设备在应用程序通知设置中具有特殊权限,允许在锁屏上显示通知。但是这个权限默认是关闭的。但在一些应用程序(如“Telegram”)中,从Google Play安装后此权限默认是打开的,我无法找到解决方案。
不确定这是否有帮助,但我在华为设备(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);