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.7K+ Learners
    4.53  (338)
    Tower of Hanoi
    1 hrs
    Beginner
    889 Learners
    4.67  (36)
    Prims Algorithm
    1 hrs
    Beginner
    928 Learners
    4.34  (62)
    Digital Clock in Python
    1 hrs
    Beginner
    2.1K+ Learners
    4.46  (100)
    KMP Algorithm
    2 hrs
    Beginner
    764 Learners
    4.58  (19)
    Electric Vehicle Design
    1 hrs
    Beginner
    9.7K+ Learners
    4.48  (579)