• Have Any Question?
  • contact@eitworld.com

Create notification





    • To create the notification, first we have to create the object of the NotificationCompact.Builder class. It is a public class.
    • We can create the notification easily by creating the object of Builder class in which we have to pass the reference of the current activity.
    • After that we have to set the contents of the notification by using the builder class object.
    • To set the icon for the notification, we use the setSmallIcon() method and pass the address of the icon which we want to display.
    • To set the title of the notification, we use the setContentTitle() method and the pass the text stream.
    • To set the message, we use the setContentText() method and pass the message in the form of string.
    • After that we have to call the build() method by using the object of the NotificationCompact.Builder class. This method return a notification and loaded with that contents which we have defined.
    • After that to issue the notification, we have to pass the returned build object by using the Notification class object means we have to assign the build() method into the reference variable of type Notification.
    • After that we have to pass the reference of getSystemService() method to it because we cannot create the object of the NotificationManager class directly.
    • Now we have to call the notify() method by using the NotificationManager class object and we have to pass the notification id as integer, and object of the Notification class.
    • We can create a notification using the following syntax:
NotificationCompat.Builder ncb = new NotificationCompat.Builder(this);
//crating the builder class object
ncb.setSmallIcon(R.drawable.yourIcon); // setting the icon
ncb.setContentTitle(“notification title”); //setting title
ncb.setContextText(” notification message”);// setting text
Notification noti = ncb.build(); //creating notification
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(0,noti); //showing notification


Real Time Web Analytics