[英]custom notification not showing on lock screen oreo
I am building Notification with remote views. 我正在构建具有远程视图的通知。 I have given NotificationCompat.VISIBILITY_PUBLIC.
我给了NotificationCompat.VISIBILITY_PUBLIC。 but Notification is not showing on lock screen in Oreo.
但通知未在Oreo的锁定屏幕上显示。
My compileSdkVersion and targetSdkVersion is 27 我的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
谢谢
尝试这个:
Notification.Builder.setVisibility(Notification.VISIBILITY_PUBLIC);
What I found working for me is in your notificationchannel you change the LockscreenVisibility to this 我发现对我有用的是在您的通知频道中,您将LockscreenVisibility更改为此
channel.LockscreenVisibility = NotificationVisibility.Public;
And in your NotificationCompat.Builder 并在您的NotificationCompat.Builder中
.setVisibility(NotificationCompat.VisibilityPublic)
You do seem to be using a slightly different Syntax as for me I had to capitalise .SetVisibility 您似乎确实使用了与我稍有不同的语法,因为我必须大写.SetVisibility
I hope this still helps. 希望对您有所帮助。
PS: Keep in mind that your phone might not allow lockscreen notifications. PS:请记住,您的手机可能不允许锁屏通知。 This also happened to me where the code worked but my phone still didn't show the notifications.
这也发生在代码可以正常工作的地方,但我的手机仍未显示通知。 ;)
;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.