Android Notification Revisited Series - Episode 1


This Series deals with the android notifications on different types and scenarios.

This Episode consists of the following

1.Create Notification for Oreo and above

2.Create Notification for Nougat and below

3.Update Notification

4.Cancel Notification

5.System wide category

6.Lock Screen Visibility

Create Notification

The creation of android notification involves the simple understanding that we have we have to add notification channel from Oreo and above.

Why Notification Channel ?

So that we can add notification to channel and user can decide the audio and priority of the channel .

For example consider an online game app with different types of notifications such as

1.Notification to show when a friend wants to play with you .

2.Notification to show your healing is done and You are ready to play .

3.Notification from app developer asking your interest to use In-App Purchase.

Imagine all the above three is associated with different respective channels and as a user you can control the channel to show with no notification tone or don’t show at all .

Let's Create Notification Channel

Create a channel by creating the channel name , description and importance and its only for Oreo and Above

Create Notification Channel

Create Notification

Create notification with NotificationManager and NotificationCompat.Builder

Create Notification for all API levels

Update Notification

One thing to note while updating Notification is using the same NotificationID while creating it.

Update NOtification with same NotificationID

Cancel Notification

To cancel a notification , just pass the NotificationID

Cancel Notification by passing NotificationId

System-Wide Category

Use system wide category for Android OS about how to handle your notification in DND mode

Since its CATEGORY_MESSAGE , system will treat as message priority in DND mode

Lock Screen Visibility

Use setVisibility() method to sow the level of Notification details in Lock screen.

You can use one of the following values

VISIBILITY_PUBLIC - shows everything

VISIBILITY_PRIVATE - shows only Notification title and icon

VISIBILITY_SECRET - will not show no information

Source Code:

Please add star if it helps you

In the next episode we will talk about Adding action button and direct reply button for Nougat and above .

Stay Hungry , Stay Foolish - YOU KNOW WHO :)

©2019 by Vignesh Prabhu.