I dont see any information about how to use NotificationCompat with Android O's Notification Channels
I do see a new Constructor that takes a channelId
but how to take a Compat notification and use it in a NotificationChannel since createNotificationChannel
takes a NotificationChannel
object
NotificationCompat.Action. Structure to encapsulate a named action that can be shown as part of this notification.
Create the NotificationChannel
only if API >= 26
public void initChannels(Context context) { if (Build.VERSION.SDK_INT < 26) { return; } NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel channel = new NotificationChannel("default", "Channel name", NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription("Channel description"); notificationManager.createNotificationChannel(channel); }
And then just use:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, "default");
So your notifications are working with both API 26 (with channel) and below (without).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With