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.4K+ Learners
    4.39  (98)
    Greedy Algorithm
    2 hrs
    Beginner
    3K+ Learners
    4.54  (581)
    Tower of Hanoi
    1 hrs
    Beginner
    920 Learners
    4.69  (42)
    Prims Algorithm
    1 hrs
    Beginner
    1K+ Learners
    4.41  (91)
    Digital Clock in Python
    1 hrs
    Beginner
    2.2K+ Learners
    4.49  (109)
    KMP Algorithm
    2 hrs
    Beginner
    792 Learners
    4.71  (28)
    Electric Vehicle Design
    1 hrs
    Beginner
    9.8K+ Learners
    4.48  (597)