How to Get Heads Up notifications in Android

How to Get Heads Up notifications in Android

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 :

[cc lang=”java”]//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);

/* Notification for oreo*/

String channelId = “channel-01”;
String channelName = “Demo”;
int importance = NotificationManager.IMPORTANCE_HIGH;

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(
channelId, channelName, importance);
notificationManager.createNotificationChannel(mChannel);
}

//to post your notification to the notification bar with an id. If a notification with the same id already exists, it will get replaced with updated information.

notificationManager.notify(0, builder.build());
[/cc]

 

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.

4 Comments

  • Marion

    29 Nov, 2016

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

  • corburterilio

    23 Dec, 2016

    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!

  • StevenInfix

    07 May, 2018

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

  • Solomonapasy

    07 May, 2018

    I love all your posts. You have done fantastic job

  • Comments are closed.

    Want to Scale
    Your Business?
    Let’s Meet & Discuss!

    Canada Flag

    CANADA

    30 Eglinton Ave W Mississauga, Ontario L5R 3E7

    India Flag

    INDIA

    3rd floor Purusharth Plaza, Amin Marg, Rajkot, Gujarat. 360002

    Get a Quote Now

    Let's delve into a thorough understanding of your challenges and explore potential solutions together