show Group Notifications - Android Android OS

Android examples for Android OS:Notification Show

Description

show Group Notifications

Demo Code

// Use of this source code is governed by the MIT license that can be found
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.NotificationCompat.WearableExtender;
import android.support.v4.app.RemoteInput;

public class Main{
    private static int NOTIFICATION_ID = 0;
    public static void showGroupNotifications(Context context, String group) {
        Notification first = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle(context.getString(R.string.page1_title))
                .setContentText(context.getString(R.string.page1_text))
                .setGroup(group).build();

        Notification second = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle(context.getString(R.string.page2_title))
                .setContentText(context.getString(R.string.page2_text))
                .setGroup(group).build();

        Notification summary = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle(context.getString(R.string.summary_title))
                .setContentText(context.getString(R.string.summary_text))
                .setGroup(group).setGroupSummary(true).build();

        NotificationManagerCompat.from(context).notify(getNewID(), first);
        NotificationManagerCompat.from(context).notify(getNewID(), second);
        NotificationManagerCompat.from(context).notify(getNewID(), summary);
    }/*from  ww w .j a v a  2s . c o  m*/
    private static synchronized int getNewID() {
        return NOTIFICATION_ID++;
    }
}

Related Tutorials