Не работает NotificationCompat.Builder
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = NotificationManagerCompat.getNotificationChannel("MyID");
if (notificationChannel == null) {
int importance = NotificationManager.IMPORTANCE_HIGH;
notificationChannel = new NotificationChannel("MyID", "Имя канала", importance);
notificationChannel.setLightColor(Color.GREEN);
notificationChannel.enableVibration(false);
NotificationManagerCompat.createNotificationChannel(notificationChannel);
}
}
new NotificationCompat.Builder(this, "MyID")
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!")
.build();
Делал все как и в этом вопросе, но ничего не работает, а "createNotificationChannel" подсвечивает как ошибку.
Источник: Stack Overflow на русском