Create Notification in 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. To see the details of the notification, the user opens the notification drawer. Both the notification area and the notification drawer are system-controlled areas that the user can view at any time.

Building Notification



Build Intent

 * Create an intent that will be fired when the user clicks the notification.
 * The intent needs to be packaged into a {@link} so that the
 * notification service can fire it on our behalf.
Intent intent = new Intent(Intent.ACTION_VIEW,
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

Setup Notification Builder

To create a notification with the support library, you create an instance of NotificationCompat.Builder and issue the notification by passing it to notify().
 * Use NotificationCompat.Builder to set up our notification.
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
		.setContentTitle("Basic Notification")

Get an instance of the NotificationManager service

 * Here we instantiate the Notification Manager object to start/stop the notifications
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

Build the notification and issues it with notification manager.

Note: notificationId is a numeric value that uniquely identifies the notification that we'll be sending

One thought on “Create Notification in Android

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s