There’s some changes to Notification in new Android O release. Now each notification goes into its channel. And your notifications won’t work if you don’t use them and have target sdk 26
Channels come only in SDK 26 and since it’s just in preview, we’re don’t need to worry so much about it yet. To test those you need to set compile and target SDK to latest ones
Notifications look exactly the same, it’s just that users have some more control over them. And the idea is actually pretty good. Hopefully people understand how it works and not only geeks.
So before to distingush notifications one from another and not replace each other you could set different ID’s for them. But to hide particular type of notifications you had to go to app. Even if they have notifications tab in settings, they could not have detailed setting to block particular notifications you don’t like.
In Android O notification channels are forced by OS, blocking ones is available when long clicked
And to see all channels you click to ALL CATEGORIES.
So imagine app that sends annoying promotion notifications almost every day. With channels you can disable that channel and keep ones for inbox or others. I have already few channels in mind: inbox, feed, server push, comments and many more
Of course everything works only if developers crate different channels, not just one. But I think it’s pretty straightforward and we will see it working
Here’s code to create new notification
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel("channelId", "Name", NotificationManager.IMPORTANCE_LOW);
int notifyID = 1;
String CHANNEL_ID = "my_channel_01";
Notification notification = new Notification.Builder(MainActivity.this)
.setContentText("You've received new messages.")
Some classes and methods are from sdk 26, so you’ll need to wrap with if statement checking for device’s Android version. I think they’ll fix it with compat library. Current latest version is
And it has setChannel in NotificationCompat.Builder class already. Couldn’t find ChannelCompat yet, I think it will come later so that you don’t need to check for api version.
That’s basically it. I’ve never did any configurations to notifications on Nougat, maybe this change will bring some use. Check here if you want to learn how to implement push notifications for your app in 5 minutes. Official doc about new notifications here.
And don’t forget to subscribe and share with friends!