我正在尝试创建本地通知,但我不明白为什么通知只显示在状态栏中,问题出在哪里?
码:
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());
您正在使用NotificationCompat
作为Builder
,但您正在使用NotificationManager
进行通知。尝试使用NotificationManagerCompat
,这应该可以解决问题。
如果需要,This link应该帮助您更好地理解。