[英]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.