Example usage for android.support.v4.app TaskStackBuilder addParentStack

List of usage examples for android.support.v4.app TaskStackBuilder addParentStack

Introduction

In this page you can find the example usage for android.support.v4.app TaskStackBuilder addParentStack.

Prototype

public TaskStackBuilder addParentStack(Class<?> sourceActivityClass) 

Source Link

Document

Add the activity parent chain as specified by manifest <meta-data> elements to the task stack builder.

Usage

From source file:Main.java

public static void showNotification(long id, String titleString, String messageString, int iconResId,
        Context context, Class<?> className) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(iconResId)
            .setContentTitle(titleString).setStyle(new NotificationCompat.BigTextStyle().bigText(messageString))
            .setContentText(messageString);
    Intent intent = new Intent(context, className);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(className);
    stackBuilder.addNextIntent(intent);/*from  www.jav  a  2  s.co m*/
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = mBuilder.build();
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify((int) id, notification);
}

From source file:org.openmrs.mobile.utilities.NotificationUtil.java

public static void notify(String title, String message) {
    Bitmap bitmap = BitmapFactory.decodeResource(OpenMRS.getInstance().getResources(), R.drawable.ic_openmrs);
    NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(
            OpenMRS.getInstance()).setSmallIcon(R.drawable.ic_openmrs).setLargeIcon(bitmap)
                    .setContentTitle(title).setContentText(message);
    Intent resultIntent = new Intent(OpenMRS.getInstance(), DashboardActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(OpenMRS.getInstance());
    stackBuilder.addParentStack(DashboardActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    mBuilder.setAutoCancel(true);//w w w .  ja  v  a 2 s . c  om
    NotificationManager mNotificationManager = (NotificationManager) OpenMRS.getInstance()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, mBuilder.build());
}

From source file:bucci.dev.freestyle.NotificationCreator.java

public static void createTimerRunningNotification(Context context, String startPauseButtonState, long timeLeft,
        TimerType timerType, boolean extraButtonVisibleState) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.bft_icon_gray)
            .setContentTitle(context.getString(R.string.notification_timer_running_text)).setAutoCancel(true)
            .setOngoing(true);/* ww  w.j  av  a2 s.c o m*/

    Intent resultIntent = new Intent(context, TimerActivity.class);
    resultIntent.putExtra(StartActivity.TIMER_TYPE, timerType);
    resultIntent.putExtra(TimerActivity.START_PAUSE_STATE_PARAM, startPauseButtonState);
    resultIntent.putExtra(TimerActivity.TIME_LEFT_PARAM, timeLeft);
    if (extraButtonVisibleState)
        resultIntent.putExtra(TimerActivity.SHOW_EXTRA_ROUND_BUTTON_PARAM, true);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(TimerActivity.class);
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);

    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(NOTIFICATION_TIMER_RUNNING, builder.build());
}

From source file:org.jorge.lolin1.func.chat.ChatNotificationManager.java

public static synchronized void createOrUpdateMessageReceivedNotification(Context context, String contents,
        Friend friend) {/*from  www .  j  a  v a  2s . co  m*/
    String name, previousNotificationContents, newContents;
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    boolean notificationFound = NOTIFICATION_ID_MAP.containsKey(name = friend.getName());
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    int id;
    if (!notificationFound) {
        builder = new NotificationCompat.Builder(context);
        id = NOTIFICATION_ID_MAP.size();
        NOTIFICATION_ID_MAP.put(name, id);
        previousNotificationContents = "";
    } else {
        id = NOTIFICATION_ID_MAP.get(name);
        previousNotificationContents = LAST_NOTIFICATION_CONTENTS.get(name);
    }
    builder.setSmallIcon(R.drawable.icon_app);
    builder.setContentTitle(name);
    builder.setStyle(new NotificationCompat.BigTextStyle()
            .bigText(newContents = previousNotificationContents + "\n" + contents));
    builder.setAutoCancel(Boolean.TRUE);
    Intent resultIntent = new Intent(context, ChatRoomActivity.class);
    resultIntent.putExtra(ChatOverviewActivity.KEY_FRIEND_NAME, name);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(ChatRoomActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    notificationManager.notify(id, builder.build());
    LAST_NOTIFICATION_CONTENTS.put(name, newContents);
}

From source file:com.myfuture.util.FavoritesNotificationReceiver.java

/**
 * Shows a notification for the given talk. Clicking the notification will
 * open the talk./*from w w  w  .j a  v a2s.c o  m*/
 */
private static void showStartNotification(Talk talk, final Context context) {
    if (!talk.isDataAvailable()) {
        throw new RuntimeException("Talk should have been fetched.");
    }

    // Set up an Intent to open the talk, with the back button going back to
    // the schedule.
    Intent talkIntent = new Intent(context, TalkActivity.class);
    talkIntent.setData(talk.getUri());
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(TalkActivity.class);
    stackBuilder.addNextIntent(talkIntent);
    PendingIntent talkPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    // Build the UI for the notification.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSmallIcon(R.drawable.light_rating_important);
    builder.setContentTitle(talk.getTitle());
    builder.setContentText("Starts in 5 minutes in " + talk.getRoom().getName());
    builder.setContentIntent(talkPendingIntent);
    builder.setAutoCancel(true);
    builder.setVibrate(VIBRATION);
    Notification notification = builder.build();

    /*
     * Display the notification. We use the label "start" to identify this
     * kind of notification. That would be useful for cancelling the
     * notification if we wanted.
     */
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify("start", talk.getObjectId().hashCode(), notification);
}

From source file:com.android.mms.widget.MmsWidgetProvider.java

/**
 * Update the widget appWidgetId//  w ww  . j av  a 2 s .  c om
 */
private static void updateWidget(Context context, int appWidgetId) {
    if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) {
        Log.v(TAG, "updateWidget appWidgetId: " + appWidgetId);
    }
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    PendingIntent clickIntent;

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, MmsWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(appWidgetId, R.id.conversation_list, intent);

    remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.sms_app_label));

    // Open Mms's app conversation list when click on header
    final Intent convIntent = new Intent(context, ConversationList.class);
    clickIntent = PendingIntent.getActivity(context, 0, convIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent(context, ComposeMessageActivity.class);
    composeIntent.setAction(Intent.ACTION_SENDTO);
    clickIntent = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addParentStack(ComposeMessageActivity.class);
    Intent msgIntent = new Intent(Intent.ACTION_VIEW);
    msgIntent.setType("vnd.android-dir/mms-sms");
    taskStackBuilder.addNextIntent(msgIntent);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list,
            taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
}

From source file:com.concentriclivers.mms.com.android.mms.widget.MmsWidgetProvider.java

/**
 * Update the widget appWidgetId//w  ww . jav  a  2s  . c o m
 */
private static void updateWidget(Context context, int appWidgetId) {
    //        if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) {
    Log.v(TAG, "updateWidget appWidgetId: " + appWidgetId);
    //        }
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    PendingIntent clickIntent;

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, MmsWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(appWidgetId, R.id.conversation_list, intent);

    remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.app_label));

    // Open Mms's app conversation list when click on header
    final Intent convIntent = new Intent(context, ConversationList.class);
    clickIntent = PendingIntent.getActivity(context, 0, convIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent(context, ComposeMessageActivity.class);
    composeIntent.setAction(Intent.ACTION_SENDTO);
    clickIntent = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addParentStack(ComposeMessageActivity.class);
    Intent msgIntent = new Intent(Intent.ACTION_VIEW);
    msgIntent.setType("vnd.android-dir/mms-sms");
    taskStackBuilder.addNextIntent(msgIntent);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list,
            taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
}

From source file:com.codefupanda.app.swish.util.NotificationUtil.java

/**
 * Show notification.//from  ww w. j  av a  2s . c  o m
 * 
 * @param context
 */
public static void showNotification(final Context context) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(context.getText(R.string.notification_title))
            .setContentText(context.getText(R.string.notification_text)).setSound(soundUri);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MainActivity.class);

    // The stack builder object will contain an artificial back stack for
    // the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);

    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    // mId allows you to update the notification later on.
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:org.peterbaldwin.vlcremote.widget.NotificationControls.java

public static void show(Context context, RemoteViews normal, RemoteViews expanded) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, PlaybackActivity.class);

    // The stack builder will contain an artificial back stack for the started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(PlaybackActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);

    boolean isTransparent = Preferences.get(context).isNotificationIconTransparent();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification n = builder.setContent(normal).setWhen(0).setOngoing(true)
            .setSmallIcon(isTransparent ? R.drawable.ic_transparent : R.drawable.ic_vlc_server).build();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        n.bigContentView = expanded;/*from  ww w .j av  a 2s. c  o  m*/
    }
    notificationManager.notify(ID, n);
}

From source file:com.dimasdanz.kendalipintu.util.CommonUtilities.java

public static void generateNotification(Context context, String message, String time, String info) {
    try {// w  w  w. j  ava 2  s .  c  om
        NotificationManager manager;
        int notificationID = 73;

        Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(),
                R.drawable.ic_stat_notification);

        Notification.Builder builder = new Notification.Builder(context);
        Intent resultIntent = new Intent(context, LogActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

        stackBuilder.addParentStack(LogActivity.class);
        stackBuilder.addNextIntent(resultIntent);

        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        Spannable sb = new SpannableString(message + " " + time + "-" + info);
        sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, message.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        builder.setAutoCancel(true);
        builder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND);
        builder.setContentTitle(context.getString(R.string.notification_title));
        builder.setContentText(sb);
        builder.setTicker(context.getString(R.string.notification_ticker));
        builder.setNumber(++msgCounter);
        builder.setSmallIcon(R.drawable.ic_stat_notification);
        builder.setLargeIcon(largeIcon);
        builder.setContentIntent(resultPendingIntent);

        if (msgCounter > 1) {
            Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
            if (msgCounter > 6) {
                name[0] = new SpannableString("...");
                name[1] = name[2];
                name[2] = name[3];
                name[3] = name[4];
                name[4] = name[5];
                name[5] = sb;
            } else {
                name[msgCounter - 1] = sb;
            }

            inboxStyle.setBigContentTitle(context.getString(R.string.notification_title));
            inboxStyle.setSummaryText(
                    msgCounter + " " + context.getString(R.string.notification_title) + " Baru");

            for (int i = name.length; i > 0; i--) {
                inboxStyle.addLine(name[i - 1]);
            }

            builder.setStyle(inboxStyle);
            builder.setContentText(msgCounter + " " + context.getString(R.string.notification_title) + " Baru");
        } else {
            name[0] = sb;
        }
        manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(notificationID, builder.build());
    } catch (NullPointerException e) {
        e.printStackTrace();
    }

}