November 9, 2015 Julie raiyani 5 Comments

Android Lollipop brings lots of good things for devices. One of the most useful things is to make the design attractive with animation by material design, along with that it also introduces a new type of notification which is known as “Heads-up notification.

When the device gets a high-priority notification, it thinks like as floating window notifications that appear at the top of the screen and will be presented to the user for short period of time with expanded layout and exposing possible actions. You can either tap them to open them or swipe them away to dismiss them. This type of notification appears only when the device is active (that is, the device is unlocked and its screen is on).

Heads-up Notification will alerts user on incoming phone call, alarm, new message, low battery, calendar based events etc.

If Notification’s priority is flagged as High, Max, or full-screen, it gets a Heads-up notification. User can also configure priority modes from

              Settings -> Sound & notification ->Interruptions

From here User can set all type of setting for Notification.

Note: Heads-up notifications were introduced in Android lollipop and + version.

Here is an example code of Heads-up notification :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//build notification
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Ping Notification")
.setContentText("Tomorrow will be your birthday.")
.setDefaults(Notification.DEFAULT_ALL) // must requires VIBRATE permission
.setPriority(NotificationCompat.PRIORITY_HIGH) //must give priority to High, Max which will considered as heads-up notification
.addAction(R.drawable.dismiss,
getString(R.string.dismiss), piDismiss)
.addAction(R.drawable.snooze,
getString(R.string.snooze), piSnooze);

//set intents and pending intents to call service on click of "dismiss" action button of notification
Intent dismissIntent = new Intent(this, MyService.class);
dismissIntent.setAction(ACTION_DISMISS);
PendingIntent piDismiss = PendingIntent.getService(this, 0, dismissIntent, 0);

//set intents and pending intents to call service on click of "snooze" action button of notification
Intent snoozeIntent = new Intent(this, MyService.class);
snoozeIntent.setAction(ACTION_SNOOZE);
PendingIntent piSnooze = PendingIntent.getService(this, 0, snoozeIntent, 0);

// Gets an instance of the NotificationManager service
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//to post your notification to the notification bar with a id. If a notification with same id already exists, it will get replaced with updated information.
notificationManager.notify(0, builder.build());

There are some issues with Heads-up Notification like below:

  • First, the “heads-up” card shows you only a tiny snippet of message-oriented notifications and provides no way to expand them and view their full contents without switching over to the source app (e.g. Hangouts, Gmail, or whatever is sending the alert).
  • If you are in the middle of doing something else on your device and don’t want to deal with an incoming “heads-up” notification right away but you want to keep it around so you’ll remember to deal with it later but you have only choice to stop what you are doing and wait about 10 seconds until the card disappears, at which point it’ll move up into your notification panel as a regular alert. If you swipe the card away, the notification will get dismissed.

If you want to disable heads-up notification, there is not any official way but you can do by a third-party app which you can find in play store.

5 People reacted on this

  1. Fantastic site. A lot of useful info here. I am sending it to a few friends ans also sharing in delicious. And naturally, thank you in your effort!

  2. It’s a great post. This site has lots of useful things, it really helped me in many ways.

  3. It’s a very good post. This site has lots of interesting things, it made it easier for me in many ways.

Comments are closed.