自定义通知在Oreo锁屏界面上没有显示

3

我正在使用远程视图构建通知。我已经设置了NotificationCompat.VISIBILITY_PUBLIC,但是在Oreo锁屏界面上没有显示通知。

我的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();

Help appreciated!!! Thanks


尝试将IMPORTANCE_LOW更改为IMPORTANCE_HIGH - Ümañg ßürmån
@user7940066 你找到任何解决方案了吗? - UrMi
@UrMi 我将 NotificationManager.IMPORTANCE_LOW 更改为 NotificationManager.IMPORTANCE_DEFAULT,将 NotificationCompat.VISIBILITY_PUBLIC 更改为 Notification.VISIBILITY_PUBLIC。 - user7940066
2个回答

2

试试这个:

Notification.Builder.setVisibility(Notification.VISIBILITY_PUBLIC);

1
我发现对我有用的是在你的通知渠道中将LockscreenVisibility更改为以下内容
channel.LockscreenVisibility = NotificationVisibility.Public;

在你的NotificationCompat.Builder中。
.setVisibility(NotificationCompat.VisibilityPublic)

你似乎在使用略微不同的语法,因为对于我来说,我必须大写 .SetVisibility。
我希望这仍然有所帮助。

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接