Notification for android

A notification is a message you can display to the user outside of your application’s normal UI. When you tell the system to issue a notification, it first appears as an icon in the notification area.In order to see the details, the user opens the notification drawer. Both the notification area and the drawer are system-controlled areas that the user can view at any time more can be found here.
notification logicchip 2

 

We can update the current notification shown or create a new one . These two things can be achieved very easily.




notification logicchip 3

 

 

The NotificationManager require a key for starting, if we use the same key over and over it updates the current notification with the same key.

 

 

In the case of using another key for NotificationManager it creates new notification instance. Like the figure.

notification logicchip 4

It also contains additional items. Sound (default or assigned tone),Vibration (control duration and pattern of vibration),Light(color and blinking delay are  controlled ) and Time (display given time) are among it

 

Creating the object

 

This code creates the object, Next part is the tittle ticker. Ticker is created using .setTicker("Ticker heading"). Ticker is the heading that displays along with the icon in notification area.




Below is an example method for notification.

The intent is for displaying the result, It can be explained. When we click the notification it opens the activity mentioned in PendingIntent. Each notification can only open one activity.

The next method shows the updating notification.

you can see by comparing the two methods keyForNotification and keyForSingleNotification++. Where keyForNotification is for updating notifications and keyForSingleNotification++ is for individual notifications.

The full code is displayed below with xml file.

 

MainActivity.java

 

 

activity_main.xml

 

You must add permission for VIBRATION. Add this to the AndroidManifest.xml file.

Don’t hesitate to comment below if you have any questions or doubts.

2 thoughts on “Notification for android

Leave a Reply

%d bloggers like this: