Open In App

Notifications in Android Oreo (8+)

Last Updated : 19 Jan, 2023
Like Article

Android Oreo has brought in a ton of changes. This also includes the way in which a user issue notifications in an app. In this article, we will discuss the changes required to be made in the notification department. The following things are to be kept in mind while issuing notifications:

  1. Designing a Notification Channel
  2. Importance of each notification channel
  3. Notification ID (different from channel id) should not be set to zero.

Before going forward, make sure this line is added to the build.gradle (Module: app) dependencies:

implementation ''

Let’s start with making a notification channel. The method below creates a notification channel: 


// Import necessary classes
import android.content.Context;
import android.os.Build;
public class Example {
    private void issueNotification()
        // Create the notification channel for Android 8.0+
        if (Build.VERSION.SDK_INT
            >= Build.VERSION_CODES.O) {
                "CHANNEL_1", "Example channel",
        // Creating the notification builder
        NotificationCompat.Builder notificationBuilder
            = new NotificationCompat.Builder(this,
        // Setting the notification's properties
            .setContentText("This is an Oreo notification!")
        // Getting the notification manager and send the
        // notification
        NotificationManager notificationManager
            = (NotificationManager)getSystemService(
        // it is better to not use 0 as notification id, so
        // used 1.
    // Helper method to create a notification channel for
    // Android 8.0+
    private void makeNotificationChannel(String channelId,
                                         String channelName,
                                         int importance)
        NotificationChannel channel
            = new NotificationChannel(
                channelId, channelName, importance);
        NotificationManager notificationManager
            = (NotificationManager)getSystemService(

Let’s see what this method does in detail.

  1. The method accepts String id, String name, int importance.
    • String id: This is the id with which you issue a notification in the notification channel. You use this exact id for multiple notifications in the same channel.
    • String name: This is the name of the channel visible when someone taps and navigate to Settings -> Apps & Notifications -> [your_app_name] -> App notifications.
    • int importance: This is the importance level of the channel. The levels are as follows:
      1. NotificationManager.IMPORTANCE_MIN – shows only in the notification shade, no sound or peek.
      2. NotificationManager.IMPORTANCE_LOW – shows everywhere, doesn’t make sound, doesn’t peek.
      3. NotificationManager.IMPORTANCE_DEFAULT – shows everywhere, makes sound but doesn’t peek.
      4. NotificationManager.IMPORTANCE_HIGH – shows everywhere, makes sound and peeks (visual interruption).
      5. NotificationManager.IMPORTANCE_MAX – this importance level is usually not used. Works similar to IMPORTANCE_HIGH.
  2. The method then creates the channel with the parameters.
  3. The setShowBadge(true) makes the notification available by the Oreo notification dot feature.
  4. Finally, the notification channel is created by the createNotificationChannel() method of NotificationManager.
    • First, the above method initially creates a notification channel with id = “CHANNEL_1” and the name “Example channel”. The id isn’t visible anywhere but the name can be viewed by opening the “App notifications” option of the App Info page.
    • Then a NotificationCompat.Builder object is made specifying the context and id as “CHANNEL_1”. A different channel id can be mentioned provided it is made with the makeNotificationChannel() method. The rest is self-explanatory. The setNumber() method shows a number in the notification dot of the app.
    • Finally, the notification id (here 1) is better to not set 0 as in cases where the notification is used for a Foreground service, it will fail to display if the id is 0. On executing the issueNotification() method, we get the following notification:

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads