Notification like whatsapp or sms app android

I want to create a Notification view just like whatsapp or sms notification.How can I achieve this.

enter image description here

What I still have

Crouton : Here you can find

this will show crouton with current activity and lower in the action bar. if my activity is not working or I am in another action, how can this be handled.

Toast : This is not like a toast. It is displayed only at the bottom or in the center.

Dialog : this can be done like this, but it will blur the application. and turn off the background. And I do not want this

Any solution would be appreciated.

thanks

+4
3

"Head Not Notificationcation" ( ​​ Android 4.3)

:

, ,

+3

android lollipop , , http://developer.android.com/guide/topics/ui/notifiers/notifications.html headup ,

.setPriority(Notification.PRIORITY_HIGH)

,

EDIT Nov-17

Notification.PRIORITY_HIGH API 26. IMPORTANCE_HIGH.

+11

This can be done through a Headsup notification. This is a feature of Andorid L so there is a demo here

Notification createNotification(boolean makeHeadsUpNotification) {
    Notification.Builder notificationBuilder = new Notification.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setPriority(Notification.PRIORITY_DEFAULT)
            .setContentTitle("Sample Notification")
            .setContentText("This is a normal notification.");

    if(Build.VERSION.SDK_INT> Build.VERSION_CODES.KITKAT)
    {
        notificationBuilder.setCategory(Notification.CATEGORY_MESSAGE);
    }
    if (makeHeadsUpNotification) {
        Intent push = new Intent();
        push.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        push.setClass(this, IndexActivity.class);

        PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
                push, PendingIntent.FLAG_CANCEL_CURRENT);
        notificationBuilder
                .setContentText("Heads-Up Notification on Android L or above.")
                .setFullScreenIntent(fullScreenPendingIntent, true);
    }
    return notificationBuilder.build();
}

you can call it like

 NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context
           .NOTIFICATION_SERVICE);
    mNotificationManager.notify(NOTIFICATION_ID, createNotification(
           true));
+6
source

Source: https://habr.com/ru/post/1609486/


All Articles