Simplest Way to Implement Notification Channel for Android 8.0 and above Download

Starting with Android 8.0 and above, all notifications MUST be assigned notification channelFor each notification channel, you can set the range of behavior that will be applied to all notifications in this channel, then the user can change these behaviors and decide which notification channels to pay attention to.

The notification channel code is available on Android Studio with API level 26 build tools. Basically, if you are using an older version, please update android studio and make sure the build tools are higher or equal API level 26,

How to create a notification channel Android 8.0

Notification channel will be ignored for all devices running Android 7 or lower.

To create a notification channel,

  1. you will need NotificaitonChannel object with a unique identifier, the name of the channel and the level of importance.
  2. If you wish, you can also create a channel description that will be displayed to users in the notification settings.
  3. Finally, you register this notification channel on NotificationManager object via createNotificationChannel ()

Creating an Android Project

So now let’s create a new Android application project from File> NewFill in all the necessary details.

In your content_main.xml file or layout file MainActivity, add the following code. We have just created a centered button that will create notifications on the click.

Create a class named and paste the following code. I’m going to explain everything after the code, you should read these codes carefully so that you can understand them.

the hack.patchversion.patchversiontutorials package;

import android.content.Context;
import android.content.ContextWrapper;
import android.os.Build;

public class NotificationHelper extends ContextWrapper {

private static final String CHANNEL_NAME = "Basic Notifications";
private static final String CHANNEL_DESCRIPTION = "Description of the notification";
private static end string CHANNEL_ID = "MyNotificationChannel";
private static NotificationManagertificationManager;
Private context database;

public NotificationHelper (Context database) {
super (base);

this.base = base;

CreateChannel ();

@RequiresApi (api = Build.VERSION_CODES.O)
private void createChannel () {
NotificationChanneltificationChannel = New NotificationChannel (CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
notificationChannel.setDescription (CHANNEL_DESCRIPTION);
notificationChannel.enableVibration (true);
notificationChannel.enableLights (true);
notificationChannel.canShowBadge ();
notificationChannel.setLockscreenVisibility (Notification.VISIBILITY_PUBLIC);
notificationChannel.setLightColor (. GetResources () GetColor (R.color.colorAccent));

. GetNotificationManager () createNotificationChannel (notificationChannel);

public NotificationManager getNotificationManager () {
if (messagesManager == null) {
messagesManager = (NotificationManager) base.getSystemService (Context.NOTIFICATION_SERVICE);

Return notifications Manager;

// now allows you to create notifications

public void notify (String message, String title) {
NotificationCompat.Builder builder = new NotificationCompat.Builder (base, CHANNEL_ID);
UritificationUri = RingtoneManager.getDefaultUri (RingtoneManager.TYPE_NOTIFICATION);

builder.setContentTitle (title);
builder.setSmallIcon (R.drawable.ic_launcher_background);
builder.setContentText (post);
builder.setSound (notificationUri);
builder.setStyle (new NotificationCompat.BigTextStyle (). bigText (message));

getNotificationManager (). notify (9001, ());


As you can see from the code above, we created the recommended constructor in our NotificaitonHelper class. It is in this constructor that we create our notification channel. Remember that constructors are called as soon as an object has been created. Inside the constructor, please check if the Android version is greater than or equal to 8, if this is the case, create a notification channel, otherwise ignore, Android will take care of everything else. As we said earlier, the notification channel must be registered in the notification manager object, as shown in the code above. If you need to explain something, please ask in the comments system below, I will answer within a few minutes or even earlier.

Then add the following code to your file.

the hack.patchversion.patchversiontutorials package;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

protected void onCreate (BundlevedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
Toolbar toolbar = findViewById (;
setSupportActionBar (toolbar);

final NotificationHelpertificationHelper = new NotificationHelper (this);

Button notifyBtn = findViewById (;

notifyBtn.setOnClickListener (new View.OnClickListener () {
public void onClick (View View) {
messagesHelper.notify (“Notification”, “Header”);




Leave a Comment

Your email address will not be published. Required fields are marked *