![](/img/trans.png)
[英]Android: The notification does not appear on the screen, only the icon in the status bar Oreo
[英]The notification appears only in the status bar Oreo version
我正在尝试创建本地通知,但我不明白为什么通知仅显示在状态栏中,问题出在哪里?
码:
NotificationManager notificationManager = (NotificationManager)context.getSystemService(NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "Channel Id";
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Ble Fitto Notifications", NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(notificationChannel);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
notificationBuilder
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("title")
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContentText("text");
notificationManager.notify(34, notificationBuilder.build());
您正在使用Builder
NotificationCompat
,但是使用NotificationManager
进行通知。 尝试使用NotificationManagerCompat
,这应该可以解决问题。
如果需要, 此链接应帮助您更多地了解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.