Example usage for android.app Notification CATEGORY_SOCIAL

List of usage examples for android.app Notification CATEGORY_SOCIAL

Introduction

In this page you can find the example usage for android.app Notification CATEGORY_SOCIAL.

Prototype

String CATEGORY_SOCIAL

To view the source code for android.app Notification CATEGORY_SOCIAL.

Click Source Link

Document

Notification category: social network or sharing update.

Usage

From source file:graaby.app.wallet.services.GcmIntentService.java

private void sendNotification(final String msg) {
    try {/*from www . ja  v  a2s.c  o  m*/
        JSONObject object = new JSONObject(msg);
        PendingIntent pendingIntent = null;
        String notificationTitle, smallContentText, smallContentInfo = "";
        int notificationImageResource = R.drawable.ic_noty_point, notificationID,
                uniquePendingId = (int) (System.currentTimeMillis() & 0xfffffff);

        SharedPreferences pref = getSharedPreferences("pref_notification", Activity.MODE_PRIVATE);

        Uri noty_sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        if (!TextUtils.isEmpty(pref.getString("notifications_new_message_ringtone", ""))) {
            noty_sound = Uri.parse(pref.getString("notifications_new_message_ringtone", ""));
        }

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSound(noty_sound)
                .setLights(0xff2ECC71, 300, 1000).setAutoCancel(Boolean.TRUE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            mBuilder.setCategory(Notification.CATEGORY_SOCIAL);

        if (pref.getBoolean("notifications_new_message_vibrate", true)) {
            mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
        }

        Intent activityIntent = new Intent();
        switch (NotificationType.getType(object.getInt(getString(R.string.field_gcm_msg_type)))) {
        case SHARE_POINTS:
            //user received points from contact
            String sender = object.getString(getString(R.string.field_gcm_name));
            int amount = object.getInt(getString(R.string.contact_send_amount));
            notificationTitle = getString(R.string.gcm_message_recieved_points);
            smallContentText = String.format(getString(R.string.gcm_message_recieved_points_content), sender,
                    amount);
            smallContentInfo = String.valueOf(amount);
            notificationImageResource = R.drawable.ic_noty_point;
            notificationID = getRandomInt(0, 50);

            mBuilder.setColor(getResources().getColor(R.color.alizarin));

            activityIntent.setClass(this, PointReceivedActivity.class);
            activityIntent.setAction(NOTIFICATION_ACTION_POINTS);
            activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg);

            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(PointReceivedActivity.class);
            stackBuilder.addNextIntent(activityIntent);

            Intent broadcastIntent = new Intent(this, GraabyBroadcastReceiver.class);
            broadcastIntent.setAction(GraabyBroadcastReceiver.ACTION_THANK);
            broadcastIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg);
            broadcastIntent.putExtra(Helper.NOTIFICATIONID, notificationID);

            PendingIntent pendingBroadcastIntent = PendingIntent.getBroadcast(this, uniquePendingId,
                    broadcastIntent, 0);

            mBuilder.addAction(R.drawable.ic_action_accept, "Say thanks", pendingBroadcastIntent);

            pendingIntent = stackBuilder.getPendingIntent(uniquePendingId, PendingIntent.FLAG_ONE_SHOT);
            break;
        case TRANSACTION:
            //user made a transaction
            amount = object.getInt(getString(R.string.contact_send_amount));
            String outlet = object.getString(getString(R.string.field_business_name));
            notificationTitle = getString(R.string.gcm_message_transaction);
            smallContentText = String.format(getString(R.string.gcm_message_transaction_content), amount,
                    outlet);
            smallContentInfo = String.valueOf(amount);
            notificationImageResource = R.drawable.ic_noty_point;
            notificationID = getRandomInt(51, 100);

            mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(smallContentText));
            mBuilder.setColor(getResources().getColor(R.color.alizarin));

            activityIntent.setClass(this, PointReceivedActivity.class);
            activityIntent.setAction(NOTIFICATION_ACTION_TX);
            activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg);
            activityIntent.putExtra(Helper.NOTIFICATIONID, notificationID);

            pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_ONE_SHOT);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                mBuilder.setCategory(Notification.CATEGORY_STATUS);
            break;
        case NEW_VOUCHER:
            //new marketplace voucher has appeared
            outlet = object.getString(getString(R.string.field_business_name));
            notificationTitle = getString(R.string.gcm_message_market);
            if (object.has("msg"))
                smallContentText = object.getString("msg") + " @ " + outlet;
            else
                smallContentText = String.format(getString(R.string.gcm_message_market_content), outlet);
            smallContentInfo = "";
            notificationImageResource = R.drawable.ic_gcm_discount;
            notificationID = NOTIFICATION_ID_NEW_MARKET;

            mBuilder.setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(String.format(getString(R.string.gcm_message_market_content), outlet)));
            mBuilder.setColor(getResources().getColor(R.color.sunflower));

            activityIntent.setClass(this, MarketActivity.class);
            activityIntent.setAction(NOTIFICATION_ACTION_NEW_DISCOUNT);
            activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg);
            activityIntent.putExtra(Helper.NOTIFICATIONID, NOTIFICATION_ID_NEW_MARKET);
            activityIntent.putExtra(Helper.MY_DISCOUNT_ITEMS_FLAG, false);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                mBuilder.setCategory(Notification.CATEGORY_PROMO);
            break;
        case NEW_FEED:
            notificationTitle = "New message";
            smallContentText = object.getString("msg");
            notificationImageResource = R.drawable.ic_noty_announcement;
            notificationID = NOTIFICATION_ID_FEED;

            activityIntent.setClass(this, FeedActivity.class);
            activityIntent.putExtra(Helper.NOTIFICATIONID, NOTIFICATION_ID_FEED);
            activityIntent.setAction(NOTIFICATION_ACTION_FEED);

            mBuilder.setColor(getResources().getColor(R.color.alizarin));

            pendingIntent = TaskStackBuilder.create(this).addNextIntentWithParentStack(activityIntent)
                    .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
            break;
        case THANK_CONTACT:
            //contact thanks you for sending points
            String thanksString = object.getString(getString(R.string.field_gcm_name));
            notificationTitle = getString(R.string.gcm_message_thanked);
            smallContentText = String.format(getString(R.string.gcm_message_thanked_small_content),
                    thanksString);
            mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(smallContentText));
            notificationImageResource = R.drawable.ic_noty_thank;
            notificationID = NOTIFICATION_ID_THANKED;
            mBuilder.setColor(getResources().getColor(R.color.belizehole));

            break;
        case CHECKIN:
            //checkin notification
            outlet = object.getString(getString(R.string.field_gcm_name));
            notificationTitle = getString(R.string.gcm_message_checkin_title);
            smallContentText = String.format(getString(R.string.gcm_message_checkin_small_content), outlet);
            notificationImageResource = R.drawable.ic_gcm_checkin;
            notificationID = NOTIFICATION_ID_CHECKIN;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                mBuilder.setCategory(Notification.CATEGORY_STATUS);
            mBuilder.setColor(getResources().getColor(R.color.wisteria));

            break;
        case INFO_NEEDED:
            notificationTitle = getString(R.string.gcm_message_meta_info_title);
            smallContentText = getString(R.string.gcm_message_meta_info_title);
            notificationImageResource = R.drawable.ic_noty_information;
            notificationID = NOTIFICATION_ID_INFO;

            mBuilder.setColor(getResources().getColor(R.color.emarald));

            activityIntent.setClass(this, ExtraInfoActivity.class);
            activityIntent.setAction(NOTIFICATION_ACTION_INFO);
            activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg);
            activityIntent.putExtra(Helper.NOTIFICATIONID, notificationID);

            pendingIntent = PendingIntent.getActivity(this, 0, activityIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            break;
        case NONE:
        default:
            notificationTitle = "";
            smallContentText = "";
            smallContentInfo = "";
            notificationID = 0;
        }

        if (pendingIntent == null)
            pendingIntent = PendingIntent.getActivity(this, 0, activityIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationManager mNotificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);

        mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), notificationImageResource))
                .setSmallIcon(R.drawable.ic_noty_graaby).setContentTitle(notificationTitle)
                .setContentText(smallContentText).setContentInfo(smallContentInfo)
                .setContentIntent(pendingIntent);

        mNotificationManager.notify(notificationID, mBuilder.build());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.example.android.wearable.wear.wearnotifications.handlers.BigPictureSocialIntentService.java

private NotificationCompat.Builder recreateBuilderWithBigPictureStyle() {

    // Main steps for building a BIG_PICTURE_STYLE notification (for more detailed comments on
    // building this notification, check StandaloneMainActivity.java):
    //      0. Get your data
    //      1. Build the BIG_PICTURE_STYLE
    //      2. Set up main Intent for notification
    //      3. Set up RemoteInput, so users can input (keyboard and voice) from notification
    //      4. Build and issue the notification

    // 0. Get your data (everything unique per Notification)
    MockDatabase.BigPictureStyleSocialAppData bigPictureStyleSocialAppData = MockDatabase
            .getBigPictureStyleData();//from ww  w  . j  a  v a2s .c  om

    // 1. Build the BIG_PICTURE_STYLE
    BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle()
            .bigPicture(
                    BitmapFactory.decodeResource(getResources(), bigPictureStyleSocialAppData.getBigImage()))
            .setBigContentTitle(bigPictureStyleSocialAppData.getBigContentTitle())
            .setSummaryText(bigPictureStyleSocialAppData.getSummaryText());

    // 2. Set up main Intent for notification
    Intent mainIntent = new Intent(this, BigPictureSocialMainActivity.class);

    PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // 3. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly
    // from the notification without entering the app.
    String replyLabel = getString(R.string.reply_label);
    RemoteInput remoteInput = new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT)
            .setLabel(replyLabel).setChoices(bigPictureStyleSocialAppData.getPossiblePostResponses()).build();

    Intent replyIntent = new Intent(this, BigPictureSocialIntentService.class);
    replyIntent.setAction(BigPictureSocialIntentService.ACTION_COMMENT);
    PendingIntent replyActionPendingIntent = PendingIntent.getService(this, 0, replyIntent, 0);

    // Enable action to appear inline on Wear 2.0 (24+). This means it will appear over the
    // lower portion of the Notification for easy action (only possible for one action).
    final NotificationCompat.Action.WearableExtender inlineActionForWear2 = new NotificationCompat.Action.WearableExtender()
            .setHintDisplayActionInline(true).setHintLaunchesActivity(false);

    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent).addRemoteInput(remoteInput)
                    // Add WearableExtender to enable inline actions
                    .extend(inlineActionForWear2).build();

    // 4. Build and issue the notification
    NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder(
            getApplicationContext());

    GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);

    // Build notification
    notificationCompatBuilder.setStyle(bigPictureStyle)
            .setContentTitle(bigPictureStyleSocialAppData.getContentTitle())
            .setContentText(bigPictureStyleSocialAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp))
            .setContentIntent(mainPendingIntent).setColor(getResources().getColor(R.color.colorPrimary))
            .setSubText(Integer.toString(1)).addAction(replyAction).setCategory(Notification.CATEGORY_SOCIAL)
            .setPriority(Notification.PRIORITY_HIGH).setVisibility(Notification.VISIBILITY_PRIVATE)
            .extend(new NotificationCompat.WearableExtender().setHintContentIntentLaunchesActivity(true));

    for (String name : bigPictureStyleSocialAppData.getParticipants()) {
        notificationCompatBuilder.addPerson(name);
    }

    return notificationCompatBuilder;
}

From source file:fr.neamar.notiflow.GcmIntentService.java

private void sendNotification(String flow, String msg, Bundle extras) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Boolean notifyOwnMessages = prefs.getBoolean("prefNotifyOwnMessages", false);
    Boolean isOwnMessage = extras.getString("own", "false").equals("true");

    String notifyType = prefs.getString("prefNotifyType", "all"); // all | mentions | private
    Boolean isMentioned = extras.getString("mentioned", "false").equals("true");
    Boolean isPrivate = extras.getString("private", "false").equals("true");

    Log.d(TAG, "New message, type " + notifyType + ", mentioned: " + isMentioned + ", private: " + isPrivate);

    if (isOwnMessage && !notifyOwnMessages) {
        Log.i(TAG, "Canceling notification (user sent): " + extras.toString());
        mNotificationManager.cancel(extras.getString("flow"), 0);
        NotificationHelper.cleanNotifications(getApplicationContext(), extras.getString("flow"));
        return;/* w  ww .j  a va  2  s.  co  m*/

    } else if (notifyType.equals("mentions") && !isMentioned && !isPrivate) {
        Log.i(TAG, "Skipping message (not mentioned): " + extras.toString());
        return;

    } else if (notifyType.equals("private") && !isPrivate) {
        Log.i(TAG, "Skipping message (not private): " + extras.toString());
        return;
    }

    Date lastNotification = NotificationHelper.getLastNotificationDate(getApplicationContext(), flow);
    NotificationHelper.addNotification(getApplicationContext(), flow, msg);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();

    Boolean silentMode = prefs.getBoolean("prefNotifySilent", false);

    if (!silentMode) {
        Date now = new Date();
        Long timeSinceLastNotification = now.getTime() - lastNotification.getTime();

        Integer frequency = Integer.parseInt(prefs.getString("prefNotifyVibrationFrequency", "15")) * 1000;
        Boolean notifyWhenActive = prefs.getBoolean("prefNotifyWhenActive", false);
        Boolean isActive = extras.getString("active", "false").equals("true");

        if (timeSinceLastNotification < frequency) {
            Log.i(TAG, "Skipping vibration -- cooldown in effect");

        } else if (isActive && !notifyWhenActive) {
            Log.i(TAG, "Skipping vibration -- user already active");

        } else {
            mBuilder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
        }
    }

    ArrayList<String> prevMessages = NotificationHelper.getNotifications(getApplicationContext(), flow);
    Integer pendingCount = prevMessages.size();

    if (pendingCount == 1) {
        // Only one notification : display using BigTextStyle for multiline.
        NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle()
                .bigText(Html.fromHtml(msg));

        mBuilder.setStyle(style);
    } else {
        // More than one notification: use inbox style, displaying up to 5 messages
        NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

        for (int i = 0; i < Math.min(pendingCount, 5); i++) {
            style.addLine(Html.fromHtml(prevMessages.get(i)));
        }

        mBuilder.setStyle(style).setContentInfo(Integer.toString(pendingCount)).setNumber(pendingCount);

        NotificationCompat.BigTextStyle pageStyle = new NotificationCompat.BigTextStyle();
        StringBuilder pageText = new StringBuilder();

        // And then add a second page for Wearables, displaying the whole pending conversation
        for (int i = pendingCount - 1; i >= 0; i--) {
            if (i < pendingCount - 1) {
                pageText.append("<br /><br />");
            }
            pageText.append(prevMessages.get(i));
        }

        pageStyle.bigText(Html.fromHtml(pageText.toString()));

        Notification secondPage = new NotificationCompat.Builder(this).setStyle(pageStyle)
                .extend(new NotificationCompat.WearableExtender().setStartScrollBottom(true)).build();

        wearableExtender.addPage(secondPage);

    }

    // Set large icon, which gets used for wearable background as well
    String avatar = extras.getString("avatar", "");
    if (!avatar.equals("")) {

        String sizeExpr = "(/\\d+/?)$";
        Boolean isCloudFront = avatar.contains("cloudfront");
        Boolean hasSize = avatar.matches(".*" + sizeExpr);

        if (isCloudFront) {
            if (!hasSize) {
                avatar += "/400";
            } else {
                avatar.replaceFirst(sizeExpr, "/400");
            }
        }

        ImageLoader imageLoader = ImageLoader.getInstance();
        Bitmap image = imageLoader.loadImageSync(avatar);

        // scale for notification tray
        int height = (int) getResources().getDimension(android.R.dimen.notification_large_icon_height);
        int width = (int) getResources().getDimension(android.R.dimen.notification_large_icon_width);
        Bitmap scaledImage = Bitmap.createScaledBitmap(image, width, height, false);

        mBuilder.setLargeIcon(scaledImage);
        wearableExtender.setBackground(image);
    }

    // Increase priority only for mentions and 1-1 conversations
    if (isMentioned || isPrivate) {
        mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
    }

    // Retrieve color
    // Default to 0x7BD3FB
    int color = Integer.parseInt(extras.getString("color", "8115195"));

    Notification notification = mBuilder.setSmallIcon(R.drawable.notification).setColor(color)
            .setContentTitle(flow).setContentText(Html.fromHtml(msg)).setAutoCancel(true)
            .setContentIntent(createClickedIntent(flow, extras)).setDeleteIntent(createDismissedIntent(flow))
            .setTicker(Html.fromHtml(msg)).setCategory(Notification.CATEGORY_SOCIAL).extend(wearableExtender)
            .build();

    mNotificationManager.notify(flow, 0, notification);
    Log.i(TAG, "Displaying message: " + extras.toString());
}

From source file:com.example.android.wearable.wear.wearnotifications.StandaloneMainActivity.java

private void generateBigPictureStyleNotification() {

    Log.d(TAG, "generateBigPictureStyleNotification()");

    // Main steps for building a BIG_PICTURE_STYLE notification:
    //      0. Get your data
    //      1. Build the BIG_PICTURE_STYLE
    //      2. Set up main Intent for notification
    //      3. Set up RemoteInput, so users can input (keyboard and voice) from notification
    //      4. Build and issue the notification

    // 0. Get your data (everything unique per Notification)
    MockDatabase.BigPictureStyleSocialAppData bigPictureStyleSocialAppData = MockDatabase
            .getBigPictureStyleData();//from  w ww .  j a  va2s . co  m

    // 1. Build the BIG_PICTURE_STYLE
    BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle()
            // Provides the bitmap for the BigPicture notification
            .bigPicture(
                    BitmapFactory.decodeResource(getResources(), bigPictureStyleSocialAppData.getBigImage()))
            // Overrides ContentTitle in the big form of the template
            .setBigContentTitle(bigPictureStyleSocialAppData.getBigContentTitle())
            // Summary line after the detail section in the big form of the template
            .setSummaryText(bigPictureStyleSocialAppData.getSummaryText());

    // 2. Set up main Intent for notification
    Intent mainIntent = new Intent(this, BigPictureSocialMainActivity.class);

    PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // 3. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly
    // from the notification without entering the app.

    // Create the RemoteInput.
    String replyLabel = getString(R.string.reply_label);
    RemoteInput remoteInput = new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT)
            .setLabel(replyLabel)
            // List of quick response choices for any wearables paired with the phone
            .setChoices(bigPictureStyleSocialAppData.getPossiblePostResponses()).build();

    // Create PendingIntent for service that handles input.
    Intent replyIntent = new Intent(this, BigPictureSocialIntentService.class);
    replyIntent.setAction(BigPictureSocialIntentService.ACTION_COMMENT);
    PendingIntent replyActionPendingIntent = PendingIntent.getService(this, 0, replyIntent, 0);

    // Enable action to appear inline on Wear 2.0 (24+). This means it will appear over the
    // lower portion of the Notification for easy action (only possible for one action).
    final NotificationCompat.Action.WearableExtender inlineActionForWear2 = new NotificationCompat.Action.WearableExtender()
            .setHintDisplayActionInline(true).setHintLaunchesActivity(false);

    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent).addRemoteInput(remoteInput)
                    // Add WearableExtender to enable inline actions
                    .extend(inlineActionForWear2).build();

    // 4. Build and issue the notification

    // Because we want this to be a new notification (not updating a previous notification), we
    // create a new Builder. Later, we use the same global builder to get back the notification
    // we built here for a comment on the post.

    NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder(
            getApplicationContext());

    GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);

    // Build notification
    notificationCompatBuilder
            // BIG_PICTURE_STYLE sets title and content
            .setStyle(bigPictureStyle).setContentTitle(bigPictureStyleSocialAppData.getContentTitle())
            .setContentText(bigPictureStyleSocialAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp))
            .setContentIntent(mainPendingIntent)
            // Set primary color (important for Wear 2.0 Notifications)
            .setColor(getResources().getColor(R.color.colorPrimary))

            .setSubText(Integer.toString(1)).addAction(replyAction).setCategory(Notification.CATEGORY_SOCIAL)
            .setPriority(Notification.PRIORITY_HIGH)

            // Hides content on the lock-screen
            .setVisibility(Notification.VISIBILITY_PRIVATE)
            // Notifies system that the main launch intent is an Activity.
            .extend(new NotificationCompat.WearableExtender().setHintContentIntentLaunchesActivity(true));

    // If the phone is in "Do not disturb mode, the user will still be notified if
    // the sender(s) is starred as a favorite.
    for (String name : bigPictureStyleSocialAppData.getParticipants()) {
        notificationCompatBuilder.addPerson(name);
    }

    Notification notification = notificationCompatBuilder.build();
    mNotificationManagerCompat.notify(NOTIFICATION_ID, notification);

    // Close app to demonstrate notification in steam.
    finish();
}

From source file:com.example.android.wearable.wear.wearnotifications.MainActivity.java

private void generateBigPictureStyleNotification() {

    Log.d(TAG, "generateBigPictureStyleNotification()");

    // Main steps for building a BIG_PICTURE_STYLE notification:
    //      0. Get your data
    //      1. Build the BIG_PICTURE_STYLE
    //      2. Set up main Intent for notification
    //      3. Set up RemoteInput, so users can input (keyboard and voice) from notification
    //      4. Build and issue the notification

    // 0. Get your data (everything unique per Notification)
    MockDatabase.BigPictureStyleSocialAppData bigPictureStyleSocialAppData = MockDatabase
            .getBigPictureStyleData();//from w  w  w .j  av a 2 s .c o  m

    // 1. Build the BIG_PICTURE_STYLE
    BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle()
            // Provides the bitmap for the BigPicture notification
            .bigPicture(
                    BitmapFactory.decodeResource(getResources(), bigPictureStyleSocialAppData.getBigImage()))
            // Overrides ContentTitle in the big form of the template
            .setBigContentTitle(bigPictureStyleSocialAppData.getBigContentTitle())
            // Summary line after the detail section in the big form of the template
            .setSummaryText(bigPictureStyleSocialAppData.getSummaryText());

    // 2. Set up main Intent for notification
    Intent mainIntent = new Intent(this, BigPictureSocialMainActivity.class);

    // When creating your Intent, you need to take into account the back state, i.e., what
    // happens after your Activity launches and the user presses the back button.

    // There are two options:
    //      1. Regular activity - You're starting an Activity that's part of the application's
    //      normal workflow.

    //      2. Special activity - The user only sees this Activity if it's started from a
    //      notification. In a sense, the Activity extends the notification by providing
    //      information that would be hard to display in the notification itself.

    // Even though this sample's MainActivity doesn't link to the Activity this Notification
    // launches directly, i.e., it isn't part of the normal workflow, a social app generally
    // always links to individual posts as part of the app flow, so we will follow option 1.

    // For an example of option 2, check out the BIG_TEXT_STYLE example.

    // For more information, check out our dev article:
    // https://developer.android.com/training/notify-user/navigation.html

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack
    stackBuilder.addParentStack(BigPictureSocialMainActivity.class);
    // Adds the Intent to the top of the stack
    stackBuilder.addNextIntent(mainIntent);
    // Gets a PendingIntent containing the entire back stack
    PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification

    // Note: For API <24 (M and below) we need to use an Activity, so the lock-screen presents
    // the auth challenge. For API 24+ (N and above), we use a Service (could be a
    // BroadcastReceiver), so the user can input from Notification or lock-screen (they have
    // choice to allow) without leaving the notification.

    // Create the RemoteInput
    String replyLabel = getString(R.string.reply_label);
    RemoteInput remoteInput = new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT)
            .setLabel(replyLabel)
            // List of quick response choices for any wearables paired with the phone
            .setChoices(bigPictureStyleSocialAppData.getPossiblePostResponses()).build();

    // Pending intent =
    //      API <24 (M and below): activity so the lock-screen presents the auth challenge
    //      API 24+ (N and above): this should be a Service or BroadcastReceiver
    PendingIntent replyActionPendingIntent;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        Intent intent = new Intent(this, BigPictureSocialIntentService.class);
        intent.setAction(BigPictureSocialIntentService.ACTION_COMMENT);
        replyActionPendingIntent = PendingIntent.getService(this, 0, intent, 0);

    } else {
        replyActionPendingIntent = mainPendingIntent;
    }

    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent).addRemoteInput(remoteInput)
                    .build();

    // 4. Build and issue the notification

    // Because we want this to be a new notification (not updating a previous notification), we
    // create a new Builder. Later, we use the same global builder to get back the notification
    // we built here for a comment on the post.

    NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder(
            getApplicationContext());

    GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);

    // 4. Build and issue the notification
    notificationCompatBuilder
            // BIG_PICTURE_STYLE sets title and content for API 16 (4.1 and after)
            .setStyle(bigPictureStyle)
            // Title for API <16 (4.0 and below) devices
            .setContentTitle(bigPictureStyleSocialAppData.getContentTitle())
            // Content for API <24 (7.0 and below) devices
            .setContentText(bigPictureStyleSocialAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp))
            .setContentIntent(mainPendingIntent)
            // Set primary color (important for Wear 2.0 Notifications)
            .setColor(getResources().getColor(R.color.colorPrimary))

            // SIDE NOTE: Auto-bundling is enabled for 4 or more notifications on API 24+ (N+)
            // devices and all Android Wear devices. If you have more than one notification and
            // you prefer a different summary notification, set a group key and create a
            // summary notification via
            // .setGroupSummary(true)
            // .setGroup(GROUP_KEY_YOUR_NAME_HERE)

            .setSubText(Integer.toString(1)).addAction(replyAction).setCategory(Notification.CATEGORY_SOCIAL)
            .setPriority(Notification.PRIORITY_HIGH)

            // Hides content on the lock-screen
            .setVisibility(Notification.VISIBILITY_PRIVATE);

    // If the phone is in "Do not disturb mode, the user will still be notified if
    // the sender(s) is starred as a favorite.
    for (String name : bigPictureStyleSocialAppData.getParticipants()) {
        notificationCompatBuilder.addPerson(name);
    }

    Notification notification = notificationCompatBuilder.build();

    mNotificationManagerCompat.notify(NOTIFICATION_ID, notification);
}