锁定屏幕上未显示自定义通知奥利奥

custom notification not showing on lock screen oreo

我正在使用远程视图构建通知。我给了NotificationCompat.VISIBILITY_PUBLIC。但奥利奥的锁定屏幕上没有显示通知。

我的compileSdkVersion和targetSdkVersion是27

 remoteViews = new RemoteViews(getPackageName(), R.layout.player_noti_layout);
 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel("default",
                getString(R.string.player_channel),
                NotificationManager.IMPORTANCE_LOW);
        channel.setDescription("Notification, Play/pause & Next/Prev");
        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        notificationmanager.createNotificationChannel(channel);
    }
    builder = new NotificationCompat.Builder(this, "default");
    Notification foregroundNote;
    // Set Icon
    foregroundNote = builder.setSmallIcon(R.drawable.ic_radio)
            .setTicker(getResources().getString(R.string.app_name))
            .setAutoCancel(false).setOngoing(true)
            .setContent(remoteViews)
            .setContentTitle("app name").setContentText("").setWhen(0).setPriority(NotificationCompat.PRIORITY_MAX)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) 
            .build();

帮助感谢!!!谢谢

试试这个:

Notification.Builder.setVisibility(Notification.VISIBILITY_PUBLIC);

我发现对我有用的是在你的 notificationchannel 中,你将 LockscreenVisibility 更改为此

channel.LockscreenVisibility = NotificationVisibility.Public;

在你的 NotificationCompat.Builder

.setVisibility(NotificationCompat.VisibilityPublic)

您使用的语法似乎确实与我略有不同,我不得不将 .SetVisibility 大写
我希望这仍然有帮助。

PS:请记住,您的 phone 可能不允许锁屏通知。这也发生在我身上,代码有效但我的 phone 仍然没有显示通知。 ;)