Custom Notification

A notification is a message or information you can display to the user outside of your Android Application. Notifications can be clicked to perform an action or to open a new activity to indicate that an event has occurred.

Custom Notification is a notification with our own designed UI, through which we can access all different default/custom controls and can interact with all the controls of notification. We can give unique feel to our application through custom notification.

There are two types of views of notification.

  1. Normal View.
  2. Big View.

Steps To Create Custom Notification

Step 1:

Create new project in Android Studio. Create three layouts. First layout with one button to create notification, second layout for displaying Normal View, third layout for displaying Big View as per our need.

Normal Notification layout.

Big Notification layout.

Show Notification layout.

Step 2:

Now after that, We need to use RemoteViews to create and deal with Custom Notification. RemoteViews is a view hierarchy which is displayed in another process.That is inflated from layout resource file, and it provides operations for change content of the inflated hierarchy. In simple terms RemoteViews is used to interact and bind custom layouts with widget and notification. And also used Broadcast to perform action of UI click.

How to set layout and how to access the controls is shown below.

BroadcastReceiver to perform action. We need to register this broadcast in application’s manifest and unregister it when activity is destroyed.

Step 3:

Method to Create Notification.

Normal View is supported in all the version but to take the advantage of Big View of notification the SDK version of device should be jelly_bean or above that. Using NotificationCompat.Builder we will set notification. WE need to set Intent into PendingIntent which is passed as an argument in Notification object.

Step 4:

Now final step to view notification in notification bar. Call showCustomNotification() on button click. When user will click this button, you will find one notification on your notification bar with different buttons.

This was the simple and easy way to create notification with custom layout without any user permission.


Juhi Patel Android Developer

I am an Android Developer at Yudiz Solutions Pvt. Ltd. I am passionate about developing applications with new ideas , new technologies and always ready to accept upcoming challenges.

Comments are closed.