Reputation: 1758
So I have ultralight app without any libs, except Crashlytics.
I want to show notifications on all versions of Android, but there is no constructor or method to set channel id for Android O+.
My code looks like this for now
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
//Some builder things
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("service_id",
context.getString(R.string.app_name),
NotificationManager.IMPORTANCE_DEFAULT);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
}
Notification notification = builder.getNotification();
NotificationManagerCompat.from(context).notify(id, notification);
Is there any compat lite lib only for notifications?
Upvotes: 1
Views: 403
Reputation: 4956
Both Notification.Builder
and NotificationCompact.Builder
can do this:
Notification.Builder(context, "channelId")
NotificationCompat.Builder(context, "channelId")
and they have setChannelId
method.
Upvotes: 2