How to send Notification in Android App

Leave a comment

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.

A blog a day challenge

Leave a comment

I am going to start with the blog a day challenge. Simply put for the next 100 days I am going to write a blog every single day without fail on any topic.

I need to invest a considerable amount of time in learning new things for career growth and my own as well. Having a regular blog should help in prioritising the activities in that direction.

Newer Entries