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.
mChannel.enableLights(true);
// Sets the notification light color for notifications posted to this
// channel, if the device supports this feature.
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
mNotificationManager.createNotificationChannel(mChannel);

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, Notification.Builder.build() 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.")
        .setSmallIcon(R.drawable.ic_notify_status)
        .setChannel(CHANNEL_ID)
        .build();
// 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());
startActivity(intent);

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);
mNotificationManager.deleteNotificationChannel(mChannel);

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

  • February 18, 2019 at 12:50 am
    Permalink

    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!

  • February 18, 2019 at 1:31 pm
    Permalink

    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!

  • February 21, 2019 at 10:53 pm
    Permalink

    Ӏ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
    it!

  • February 22, 2019 at 3:22 pm
    Permalink

    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!

  • February 22, 2019 at 11:09 pm
    Permalink

    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!

  • February 23, 2019 at 9:08 pm
    Permalink

    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!

  • February 24, 2019 at 12:38 am
    Permalink

    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!

    • Lovish
      February 24, 2019 at 11:40 pm
      Permalink

      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.

  • February 28, 2019 at 8:30 pm
    Permalink

    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!

    • Lovish
      March 3, 2019 at 12:26 pm
      Permalink

      Thank you for your response. I’ll let you know asap if I come across any good blog.

  • Lovish
    March 3, 2019 at 12:24 pm
    Permalink

    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.

  • March 7, 2019 at 12:25 am
    Permalink

    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!

    Thanks!

  • March 15, 2019 at 1:57 am
    Permalink

    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.

    Cһeers!

Leave a Reply