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. Try using NotificationManagerCompat
, this should solve the issue.
This link should help you with more understanding if required.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.