Wednesday, July 17, 2024
notification channelsnotification groupstech

Notification Channels : Android O Features and Implementation.

Spread the love

Google is here with yet another update to ease our lives,Oh yes, it’s introducing a new feature for Android O ,any guesses?….”Notification Channels”- to provide an integrated system to help users manage notifications. Isn’t it a great idea to group the notifications into channels that offer users greater control over apps notification categories!
Users can now manage most of the settings associated with notifications using system UI. The user can modify the behavior for any characteristic like Importance ,Sounds, Lights, Vibrations, Show on lock screen, Override do not disturb.
Long press to change the behavior of notification channel or even to block it.

Some of the features are:
  1. Block all notifications of app. This means notifications from app never been shown on user device.
  2. The user can state whether or not app notifications should be shown on app icon as a badge.
  3. User can also have the feature to group notification channel into separate groups. For Example, any application may support Personal or Business mode, or Child and Parent mode . This gives the option to manage notifications settings across multiple groups.

Creating a Notification Channel:

  1. Construct a notification channel group with an ID.
  2. Configure the notification channel object with any desired initial setting like alert sounds.
  3. Submit it to notification manager.
NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// The id of the channel.
String id = "my_channel_01";
// The user visible name of the channel.
CharSequence name = getString(R.string.channel_name);
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
// Configure the notification channel.
// Sets the notification light color for notifications posted to this
// channel, if the device supports this feature.
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});

Creating a Notification Channel Group:

If the app supports multiple user accounts, notification channel can be created for each account. It allows to manage multiple channels with identical names within a single app. Each notification channel group requires n ID that must be unique within a a package.
Following is the code showing how to implement notification channel group.
// The id of the group.
String group = "my_group_01";
// The user visible name of the group.
CharSequence name = getString(R.string.group_name);;
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.createNotificationChannelGroup(new NotificationChannelGroup(group, name));

Creating a Notification:

To create notification, method is called, which returns which rerurns a notification object according to specifications given.To issue the notification, NotificationManager.notify() is a method to be called.
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Sets an ID for the notification, so it can be updated.
int notifyID = 1;
// The id of the channel.
String CHANNEL_ID = "my_channel_01";
// Create a notification and set the notification channel.
Notification notification = new Notification.Builder(MainActivity.this)
        .setContentTitle("New Message")
        .setContentText("You've received new messages.")
// Issue the notification.
mNotificationManager.notify(id, notification);

 Reading Notification Channel Settings:

NotificationManager.getNotificationChannel() method is used to retrieve a single notification channel.
NotificationManager.getNotificationChannels() method is used to retrive all notification channels belonging to app.

Updating Notification Channel Settings:

Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_CHANNEL_ID, mChannel.getId());
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());

Deleting a Notification Channel:

NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// The id of the channel.
String id = "my_channel_01";
NotificationChannel mChannel = mNotificationManager.getNotificationChannel(id);

About The Author

15 thoughts on “Notification Channels : Android O Features and Implementation.

  • Roland

    I tгuly love your site.. Excellent colors & theme.
    Did you make this sіte yourself? Please reply back as I’m wanting to ϲreate my own website and would love to fіnd out whеre you
    ցot this from or exactly what the theme is named. Thank you!

  • Lorna

    Wonderful website. Plenty of helpful іnfo here. I’m sending it to
    some pals ans also sharing in delіcious.

    And of course, thank you in your sweat!

  • Selma

    Ӏt is appropriate time tо make some plans for the future and it’s time to be happy.
    Ӏ’ѵe read this post and if I could I desire to suggest you some interesting things
    or suggestіons. Perhaps you could write next articles
    referring to this article. I deѕire to read even more tһings about

  • Tyler

    I aƅsolutely love your site.. Pleasant colors & theme. Did you develop
    this amazing site уourself? Please reply back as I’m attempting to create my ⲟwn site ɑnd
    would love to knoԝ where you got this from or what
    the theme is called. Thanks!

  • Marina

    This is tһe right site for anybody who really wants to understand
    thiѕ topic. You reaⅼize so much its aⅼmoѕt tough to argue with you (not that I personally will need to…HaHa).
    Yⲟu definitely put a neᴡ spin on a topic that’s been written about for a long time.
    Great stuff, just excellent!

  • Louan

    Heу there! I coulԁ have sworn I’ve been to this website
    befⲟre but after browsing through some of the post I realizeԁ
    it’s new to me. Anyways, I’m definitely ɗeⅼighted I found it and I’ll be book-marking and
    checking back often!

  • Bryan

    Hey theгe are using WordPress for your site platform?
    I’m new to the blog world but I’m trying to ɡet started and set up my own. Do you need any coding ҝnowledge
    to maке your own blog? Any help would be greatly appreciated!

    • Hi, you don’t require coding knowledge if you’re getting started with WordPress. But it would be better if at least you understand basic HTML and basic coding syntax.

  • Shelley

    Hello! Τhis is my 1st comment here so I
    just wanted to give a quick shout out and say I genuinely enjoy
    reading through your blog posts. Cаn you recommend any other bloɡs/websites/forums that go
    over the same topics? Thank you ѕo much!

  • The issue is with the Images, please click on the Image to enlarge and check in case if you face the same issue please reach us directly.

  • Stephendy

    My brother recommended I migһt like this web site. He was totally right.
    Thіs post actually made mү day. Yօu can not imagine just how much time I had sρеnt for thіs info!


  • Stephany

    Hi there, just became аlert to your blog through Gⲟogle, and found that it is really informative.

    I am gonna ᴡatch out for brussels. Ι’ll appreciate if
    you continue this in future. Lots of people will be benefiteԀ from your writing.


Leave a Reply