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

    Convert Video to GIF in Python
    1 hrs
    Beginner
    2.2K+ Learners
    4.36  (59)
    Basics of Graph Theory
    2 hrs
    Beginner
    1.5K+ Learners
    4.61  (61)
    Lambda Expression in Java
    1 hrs
    Intermediate
    2K+ Learners
    4.53  (68)
    Greedy Algorithm
    2 hrs
    Beginner
    1.9K+ Learners
    4.56  (87)
    Tower of Hanoi
    1 hrs
    Beginner
    790 Learners
    4.74  (27)
    Prims Algorithm
    1 hrs
    Beginner
    783 Learners
    4.64  (36)
    Digital Clock in Python
    1 hrs
    Beginner
    1.9K+ Learners
    4.48  (82)
    KMP Algorithm
    2 hrs
    Beginner
    693 Learners
    4.6  (15)
    Electric Vehicle Design
    1 hrs
    Beginner
    9.3K+ Learners
    4.52  (447)
    Great Learning Career Kickstarter Test - Software Development
    1 hrs
    Beginner
    469 Learners
    4.0  (4)