Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create pop-up notifications like the notification used in whatsapp for android?

I want to create notification like the pop-up notification used in WhatsApp application for android devices.

How can i do it? Since i am a new user I cannot upload the screen shot

please refer this link : http://cdn6.staztic.com/cdn/screenshot/appsdroidnotifythemeicecreamsandwich-1-1.jpg

enter image description here

for the screen shot image and help me :)

like image 420
Hari Nadar Avatar asked Sep 03 '12 09:09

Hari Nadar


People also ask

What is the use of popup notification in WhatsApp?

A popup notification is a message that appears on your users' browser or desktop. They're designed to grab your audience's attention and engage them in some way.

What are pop up notifications called?

The terms pop-up notification, toast, passive pop-up, snackbar, desktop notification, notification bubble, or simply notification all refer to a graphical control element that communicates certain events to the user without forcing them to react to this notification immediately, unlike conventional pop-up windows.

Why is pop up notification in WhatsApp no longer available?

Make sure Do not disturb is turned off or you have allowed WhatsApp notifications in priority mode in your phone's Settings app > Sound > Do not disturb. Make sure all of WhatsApp's permissions are granted in your phone's Settings app > Apps > WhatsApp > Permissions.


1 Answers

They're called 'heads-up' notifications. This page has a nice explanation.

To summarize, set the priority to High (or Max).

Here is an example in my code:

public static void notify(Context context, int id, int titleResId,
                          int textResId, PendingIntent intent) {
    NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    String title = context.getString(titleResId);
    String text = context.getString(textResId);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.notification)
            .setContentTitle(title)
            .setContentText(text)
            .setDefaults(Notification.DEFAULT_ALL)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setAutoCancel(true)
            .setWhen(System.currentTimeMillis())
            .setTicker(title)
            .setContentIntent(intent);
    notificationManager.notify(id, builder.build());
}
like image 107
Timores Avatar answered Sep 19 '22 11:09

Timores