简体   繁体   English

该通知仅出现在状态栏Oreo版本中

[英]The notification appears only in the status bar Oreo version

I am trying to create a local notification, but I do not understand why the notification is only displayed in the status bar, where is the problem? 我正在尝试创建本地通知,但我不明白为什么通知仅显示在状态栏中,问题出在哪里?

Code: 码:

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

You are using NotificationCompat for the Builder but you are using NotificationManager for notifying. 您正在使用Builder NotificationCompat ,但是使用NotificationManager进行通知。 Try using NotificationManagerCompat , this should solve the issue. 尝试使用NotificationManagerCompat ,这应该可以解决问题。

This link should help you with more understanding if required. 如果需要, 此链接应帮助您更多地了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM