Redeem Now
Read More
Read now

How Push Notification works in android

How Push Notification works in android

In this blog we will read how  push Notification  works in Android . Notification is just like a message that you can show outside of your app.You can expand notification by clicking onto it.And If user do not want to get notification  he can also disable notification for each application.  you can also read overview from android Notification

activity_main

In xml we  take 3 edit Text . we put title in title_et ,  subject in subject_et and body of notification in body_et.

NotificationManager

Android provide Notification Manager class for sending notification  purpose and You can initiate this class by getSystemService() method.

Notification.Builder

The Builder provides an builder interface to create Notification object.You can set Notification Title , subject ,body and icon.You must enter icon to notification object . if you will not provide icon then It will crash so you need to provide notification icon.

Set Android Notification Properties

The properties of Android notification are set using Notification.Builder object. Some of the notification properties are mention below:

  • setContentTitle(): It is used to set the title of notification.If you want to set title of notification so you can use set content title by using this method
  • setContentText(): It is used to set the text message.If you want to set text to notification so you can set context text by using this method.
  • setSmallIcon(): It sets the icon of notification. It is used to set icon to your notification so you can set icon by using this method.
  • setPriority(): It sets the priority of notification.It is used to set priority to your notification so you can use this method to set priority.

Notify

And at the last we need to notify to Notification Manager and notification will sent.

MainActivity

In Main Activity you can see code for Notification so we provide here this Activity.

 

Let us run application and test for Notification.We have added image please check notification

You can drag to bottom and check notification . please check image for notifcation.

And thanks for reading this blog, You can get other blogs from here

 

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close