Get A Quote
9Nov 2015

How to Get Heads Up notifications in Android

4 Comments   Android, ASP.Net
android_headup_blog

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

When device gets high-priority notification, it think like as floating window notifications that appear at the top of the screen and will presented to 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 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.

 

notificatio_priority

[ Note : Heads-up notifications introduce in Android lollipop and + version.]

Here is example code of Heads-up notification :

For more detail on Notification refer my previous blog Different Types Of Notification Android

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());

Output :

handsup_notification

 

There is some issues with Heads-up Notification like as 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 third party app which you can find in play store.

Brevity

About Admin

Brevity Software provides services such as : Web design and development, Mobile application development, Web application development, Travel portal development, Event management systems, Transport & Logistics Software, Enterprise Mobility Solutions, eCommerce & M Commerce application and many more.

4 thoughts on “How to Get Heads Up notifications in Android

  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. goo.gl says:

    Very good blog post. I certainly appreciate this site.
    Stick with it!

  3. Mickeyovddvr says:

    I see your website needs some fresh & unique content. Writing manually is time consuming, but there is tool for this task.

  4. Thank you for giving the information. It’ll help me
    lot.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>