通知仅显示在状态栏Oreo版本中

问题描述 投票:0回答:1

我正在尝试创建本地通知,但我不明白为什么通知只显示在状态栏中,问题出在哪里?

码:

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());
android notifications
1个回答
1
投票

您正在使用NotificationCompat作为Builder,但您正在使用NotificationManager进行通知。尝试使用NotificationManagerCompat,这应该可以解决问题。

如果需要,This link应该帮助您更好地理解。

© www.soinside.com 2019 - 2024. All rights reserved.