We are going to do a quick tutorial today on how we can generate notifications in Android. Although the standard Android Guide does explain it, but I dont think its a very quick way to understand stuff.

So here we go.

Here are the basic steps –

  1. Create a notification channel
  2. Build a notification
  3. Send a notitification.

How do we create a notitification channel, we do it simply by keeping in mind that we need a unique channel id(“1000111”) and channel name(“cld_notif_channel”). The values do not matter, however they need to be unique.

The notitification channel can be invoked as many number times as required, although once invoked and available it will just not create another if its already present. I would suggest to create your notitification channels as soon as your application opens.

The way you do it is simply by calling the createNotificationChannel() function in your Main Activity.

Step 2 involves creating the notification itself. There are few basic things we need to take care of, it must have a Small Icon available, this one is mandatory along with the Channel Id, which we created above.

Step 2.5 involves creating a notification manager which is actually going to be responsible for sending out notifications.

Step 3 involves obviously firing the notification and sadly this again requires a unique id(“1001”) to uniquely identify the notification and send it.

And there you go, its so simple it hardly would take 10 minutes of your time to learn how to send notifications in your Android application.

*Note – where you see *this* that is android.content.Context so this goes inside your class for the activity.