Android

Android Notifications

Android Notifications

A Notification is just like a message that is shown to the user outside the main application’s interface. You can also configure notifications that will show the notification for that application in the notification area. In Android, the Toast class is used to show alerts to the users but for a very short period and after that the notification gets disappeared. 

Let’s see how you can create and send notifications in Android:

Step – 1: First we need to create a notification builder with the help of NotificationCompat.Builder.build(). After creating a notification builder, you can use it to set various notification properties such as the icon size, sound, title etc. 

Step – 2: As we just discussed that we can set notification properties in our notification builder. But a few properties are most important to set in the notification builder as follows:

An icon to be set using setSmallIcon()
A detailed text for that notification by using setContentText()
A title for that notification using setContentTitle()

Step – 3: Now, we are going to attach some actions with the notification. The action will take the user directly into the application. To define the action, PendingIntent is used to start the activity in the application. 

Step – 4: At last, you pass the notification to the user by calling NotificationManager.notify(). But you need to make sure that NotificationCompat.Builder.build() method is called before notifying NotificationManager.notify(). 
 

Top course recommendations for you

    Lambda Expression in Java
    1 hrs
    Intermediate
    2.3K+ Learners
    4.37  (87)
    Greedy Algorithm
    2 hrs
    Beginner
    2.9K+ Learners
    4.55  (521)
    Tower of Hanoi
    1 hrs
    Beginner
    901 Learners
    4.67  (36)
    Prims Algorithm
    1 hrs
    Beginner
    957 Learners
    4.32  (75)
    Digital Clock in Python
    1 hrs
    Beginner
    2.1K+ Learners
    4.47  (101)
    KMP Algorithm
    2 hrs
    Beginner
    778 Learners
    4.67  (24)
    Electric Vehicle Design
    1 hrs
    Beginner
    9.7K+ Learners
    4.48  (588)