Reputation: 1
In my app i have set min API level to 19 and target level to 26 (Oreo). Now, when I try to create a notification without a notification channel, it does not work because a notification channel is required when target API level is 26. But when I try to create the notification channel the IDE complains that creating a notification channel requires min API level 26.
How should I go about this? I would not want the set the minimum level to 26.
Upvotes: 0
Views: 1460
Reputation: 21
You don't have to set the minimum API level to 26. You can check the API level at runtime to conditionally call createNotificationChannel
when the API level is equal to or greater than Android 8.0 (API level 26)
if (Build.VERSION.SDK_INT >= 26) {
NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID,
CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
notificationManager.createNotificationChannel(notificationChannel);
notification = new Notification.Builder(this, CHANNEL_ID)
.setContentTitle("title...")
.setContentText("message...")
.setSmallIcon(R.drawable.ic_notification)
.setContentIntent(pendingIntent)
.build();
}
Upvotes: 1