Example usage for android.app PendingIntent FLAG_CANCEL_CURRENT

List of usage examples for android.app PendingIntent FLAG_CANCEL_CURRENT

Introduction

In this page you can find the example usage for android.app PendingIntent FLAG_CANCEL_CURRENT.

Prototype

int FLAG_CANCEL_CURRENT

To view the source code for android.app PendingIntent FLAG_CANCEL_CURRENT.

Click Source Link

Document

Flag indicating that if the described PendingIntent already exists, the current one should be canceled before generating a new one.

Usage

From source file:com.money.manager.ex.sync.SyncManager.java

private PendingIntent getPendingIntentForDelayedUpload() {
    DatabaseMetadata db = getDatabases().getCurrent();

    Intent intent = new Intent(getContext(), SyncService.class);

    intent.setAction(SyncConstants.INTENT_ACTION_SYNC);

    intent.putExtra(SyncConstants.INTENT_EXTRA_LOCAL_FILE, db.localPath);
    intent.putExtra(SyncConstants.INTENT_EXTRA_REMOTE_FILE, db.remotePath);

    return PendingIntent.getService(getContext(), SyncConstants.REQUEST_DELAYED_SYNC, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
}

From source file:com.sonetel.service.SipNotifications.java

public void showNotificationForVoiceMail(SipProfile acc, int numberOfMessages) {
    if (messageVoicemail == null) {

        messageVoicemail = new NotificationCompat.Builder(context);
        messageVoicemail.setSmallIcon(android.R.drawable.stat_notify_voicemail);
        messageVoicemail.setTicker(context.getString(R.string.voice_mail));
        messageVoicemail.setWhen(System.currentTimeMillis());
        messageVoicemail.setDefaults(Notification.DEFAULT_ALL);
        messageVoicemail.setAutoCancel(true);
        messageVoicemail.setOnlyAlertOnce(true);
    }/* w w  w.  j a  v  a 2  s. c  om*/

    PendingIntent contentIntent = null;
    Intent notificationIntent;
    if (acc != null && !TextUtils.isEmpty(acc.vm_nbr) && acc.vm_nbr != "null") {
        notificationIntent = new Intent(Intent.ACTION_CALL);
        notificationIntent.setData(
                SipUri.forgeSipUri(SipManager.PROTOCOL_CSIP, acc.vm_nbr + "@" + acc.getDefaultDomain()));
        notificationIntent.putExtra(SipProfile.FIELD_ACC_ID, acc.id);
    } else {
        notificationIntent = new Intent(SipManager.ACTION_SIP_DIALER);
    }
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    String messageText = "";
    if (acc != null) {
        messageText += acc.getProfileName() + " : ";
    }
    messageText += Integer.toString(numberOfMessages);

    messageVoicemail.setContentTitle(context.getString(R.string.voice_mail));
    messageVoicemail.setContentText(messageText);
    if (contentIntent != null) {
        messageVoicemail.setContentIntent(contentIntent);
        notificationManager.notify(VOICEMAIL_NOTIF_ID, messageVoicemail.getNotification());
    }
}

From source file:org.adaway.service.ApplyService.java

private void updateApplyNotification(Context context, String contentTitle, String contentText) {
    // configure the intent
    Intent intent = new Intent(mService, BaseActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(mService.getApplicationContext(), 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    int icon = R.drawable.status_bar_icon;

    // add app name to title
    String contentTitleWithAppName = mService.getString(R.string.app_name) + ": " + contentTitle;

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(icon)
            .setContentTitle(contentTitleWithAppName).setContentText(contentText);

    mNotificationManager.notify(APPLY_NOTIFICATION_ID, mBuilder.build());

    mBuilder.setContentIntent(contentIntent);

    // update status in BaseActivity with Broadcast
    BaseActivity.setStatusBroadcast(mService, contentTitle, contentText, StatusCodes.CHECKING);
}

From source file:org.adawaycn.service.ApplyService.java

private void updateApplyNotification(Context context, String contentTitle, String contentText) {
    // configure the intent
    Intent intent = new Intent(mService, BaseActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(mService.getApplicationContext(), 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    int icon = R.drawable.status_bar_icon;

    // add app name to title
    String contentTitleWithAppName = mService.getString(R.string.app_name) + ": " + contentTitle;

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(icon)
            .setContentTitle(contentTitleWithAppName).setContentText(contentText);

    mNotificationManager.notify(APPLY_NOTIFICATION_ID, mBuilder.build());

    mBuilder.setContentIntent(contentIntent);
    // update status in BaseActivity with Broadcast
    BaseActivity.setStatusBroadcast(mService, contentTitle, contentText, StatusCodes.CHECKING);
}

From source file:com.google.samples.apps.sergio.service.SessionAlarmService.java

private void notifySession(final long sessionStart, final long alarmOffset) {
    long currentTime = UIUtils.getCurrentTime(this);
    final long intervalEnd = sessionStart + MILLI_TEN_MINUTES;
    LOGD(TAG, "Considering notifying for time interval.");
    LOGD(TAG, "    Interval start: " + sessionStart + "=" + (new Date(sessionStart)).toString());
    LOGD(TAG, "    Interval end: " + intervalEnd + "=" + (new Date(intervalEnd)).toString());
    LOGD(TAG, "    Current time is: " + currentTime + "=" + (new Date(currentTime)).toString());
    if (sessionStart < currentTime) {
        LOGD(TAG, "Skipping session notification (too late -- time interval already started)");
        return;/* w  w  w.  j ava  2 s .c  om*/
    }

    if (!PrefUtils.shouldShowSessionReminders(this)) {
        // skip if disabled in settings
        LOGD(TAG, "Skipping session notification for sessions. Disabled in settings.");
        return;
    }

    // Avoid repeated notifications.
    if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this,
            ScheduleContract.Blocks.generateBlockId(sessionStart, intervalEnd))) {
        LOGD(TAG, "Skipping session notification (already notified)");
        return;
    }

    final ContentResolver cr = getContentResolver();

    LOGD(TAG, "Looking for sessions in interval " + sessionStart + " - " + intervalEnd);
    Cursor c = cr.query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, SessionDetailQuery.PROJECTION,
            ScheduleContract.Sessions.STARTING_AT_TIME_INTERVAL_SELECTION,
            ScheduleContract.Sessions.buildAtTimeIntervalArgs(sessionStart, intervalEnd), null);
    int starredCount = c.getCount();
    LOGD(TAG, "# starred sessions in that interval: " + c.getCount());
    String singleSessionId = null;
    String singleSessionRoomId = null;
    ArrayList<String> starredSessionTitles = new ArrayList<String>();
    while (c.moveToNext()) {
        singleSessionId = c.getString(SessionDetailQuery.SESSION_ID);
        singleSessionRoomId = c.getString(SessionDetailQuery.ROOM_ID);
        starredSessionTitles.add(c.getString(SessionDetailQuery.SESSION_TITLE));
        LOGD(TAG, "-> Title: " + c.getString(SessionDetailQuery.SESSION_TITLE));
    }
    if (starredCount < 1) {
        return;
    }

    // Generates the pending intent which gets fired when the user taps on the notification.
    // NOTE: Use TaskStackBuilder to comply with Android's design guidelines
    // related to navigation from notifications.
    Intent baseIntent = new Intent(this, MyScheduleActivity.class);
    baseIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    TaskStackBuilder taskBuilder = TaskStackBuilder.create(this).addNextIntent(baseIntent);

    // For a single session, tapping the notification should open the session details (b/15350787)
    if (starredCount == 1) {
        taskBuilder.addNextIntent(
                new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri(singleSessionId)));
    }

    PendingIntent pi = taskBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);

    final Resources res = getResources();
    String contentText;
    int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000;
    if (minutesLeft < 1) {
        minutesLeft = 1;
    }

    if (starredCount == 1) {
        contentText = res.getString(R.string.session_notification_text_1, minutesLeft);
    } else {
        contentText = res.getQuantityString(R.plurals.session_notification_text, starredCount - 1, minutesLeft,
                starredCount - 1);
    }

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText)
            .setColor(getResources().getColor(R.color.theme_primary))
            .setTicker(res.getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount))
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS,
                    SessionAlarmService.NOTIFICATION_LED_OFF_MS)
            .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi)
            .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true);
    if (minutesLeft > 5) {
        notifBuilder.addAction(R.drawable.ic_alarm_holo_dark,
                String.format(res.getString(R.string.snooze_x_min), 5),
                createSnoozeIntent(sessionStart, intervalEnd, 5));
    }
    if (starredCount == 1 && PrefUtils.isAttendeeAtVenue(this)) {
        notifBuilder.addAction(R.drawable.ic_map_holo_dark, res.getString(R.string.title_map),
                createRoomMapIntent(singleSessionRoomId));
    }
    String bigContentTitle;
    if (starredCount == 1 && starredSessionTitles.size() > 0) {
        bigContentTitle = starredSessionTitles.get(0);
    } else {
        bigContentTitle = res.getQuantityString(R.plurals.session_notification_title, starredCount, minutesLeft,
                starredCount);
    }
    NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder)
            .setBigContentTitle(bigContentTitle);

    // Adds starred sessions starting at this time block to the notification.
    for (int i = 0; i < starredCount; i++) {
        richNotification.addLine(starredSessionTitles.get(i));
    }
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    LOGD(TAG, "Now showing notification.");
    nm.notify(NOTIFICATION_ID, richNotification.build());
}

From source file:com.roamprocess1.roaming4world.service.SipNotifications.java

public void showNotificationForVoiceMail(SipProfile acc, int numberOfMessages) {
    if (messageVoicemail == null) {

        messageVoicemail = new NotificationCompat.Builder(context);
        messageVoicemail.setSmallIcon(android.R.drawable.stat_notify_voicemail);
        messageVoicemail.setTicker(context.getString(R.string.voice_mail));
        messageVoicemail.setWhen(System.currentTimeMillis());
        messageVoicemail.setDefaults(Notification.DEFAULT_ALL);
        messageVoicemail.setAutoCancel(true);
        messageVoicemail.setOnlyAlertOnce(true);
    }// w  w w.ja  va 2s  .c  om

    PendingIntent contentIntent = null;
    Intent notificationIntent;
    if (acc != null && !TextUtils.isEmpty(acc.vm_nbr) && acc.vm_nbr != "null") {
        notificationIntent = new Intent(Intent.ACTION_CALL);
        notificationIntent.setData(
                SipUri.forgeSipUri(SipManager.PROTOCOL_CSIP, acc.vm_nbr + "@" + acc.getDefaultDomain()));
        notificationIntent.putExtra(SipProfile.FIELD_ACC_ID, acc.id);
    } else {
        notificationIntent = new Intent(SipManager.ACTION_SIP_DIALER);
    }
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    String messageText = "";
    if (acc != null) {
        messageText += acc.getProfileName() + " : ";
    }
    messageText += Integer.toString(numberOfMessages);

    messageVoicemail.setContentTitle(context.getString(R.string.voice_mail));

    System.out.println("SipNotifications  messageText  " + messageText);

    messageVoicemail.setContentText(messageText);
    if (contentIntent != null) {
        messageVoicemail.setContentIntent(contentIntent);
        notificationManager.notify(VOICEMAIL_NOTIF_ID, messageVoicemail.build());
    }
}

From source file:com.ubergeek42.WeechatAndroid.service.RelayServiceBackbone.java

/** try connect once
 ** @return true if connection attempt has been made and false if connection is not possible */
private boolean connect() {
    if (DEBUG_CONNECTION)
        logger.debug("connect()");

    // only connect if we aren't already connected
    if ((connection != null) && (connection.isConnected()))
        return false;

    if (connection != null)
        connection.disconnect();/*w ww. ja  v  a 2 s  . com*/

    // load the preferences
    host = prefs.getString(PREF_HOST, null);
    pass = prefs.getString(PREF_PASSWORD, null);
    port = Integer.parseInt(prefs.getString(PREF_PORT, "8001"));

    // if no host defined, signal user to edit their preferences
    if (host == null || pass == null) {
        Intent i = new Intent(this, WeechatPreferencesActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
        showNotification(getString(R.string.notification_update_settings_details),
                getString(R.string.notification_update_settings), contentIntent);
        return false;
    }

    NetworkInfo networkInfo = connectivityManager().getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnected()) {
        Intent i = new Intent(this, WeechatActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
        showNotification(getString(R.string.notification_network_unavailable_details),
                getString(R.string.notification_network_unavailable), contentIntent);
        network_unavailable = true;
        return false;
    }

    IConnection conn;
    String connType = prefs.getString(PREF_CONNECTION_TYPE, PREF_TYPE_PLAIN);
    if (connType.equals(PREF_TYPE_SSH)) {
        SSHConnection tmp = new SSHConnection(host, port);
        tmp.setSSHHost(prefs.getString(PREF_SSH_HOST, ""));
        tmp.setSSHPort(prefs.getString(PREF_SSH_PORT, "22"));
        tmp.setSSHUsername(prefs.getString(PREF_SSH_USER, ""));
        tmp.setSSHKeyFile(prefs.getString(PREF_SSH_KEYFILE, ""));
        tmp.setSSHPassword(prefs.getString(PREF_SSH_PASS, ""));
        conn = tmp;
    } else if (connType.equals(PREF_TYPE_STUNNEL)) {
        StunnelConnection tmp = new StunnelConnection(host, port);
        tmp.setStunnelCert(prefs.getString(PREF_STUNNEL_CERT, ""));
        tmp.setStunnelKey(prefs.getString(PREF_STUNNEL_PASS, ""));
        conn = tmp;
    } else if (connType.equals(PREF_TYPE_SSL)) {
        SSLConnection tmp = new SSLConnection(host, port);
        tmp.setSSLKeystore(certmanager.sslKeystore);
        conn = tmp;
    } else if (connType.equals(PREF_TYPE_WEBSOCKET)) {
        WebSocketConnection tmp = new WebSocketConnection(host, port, false);
        conn = tmp;
    } else if (connType.equals(PREF_TYPE_WEBSOCKET_SSL)) {
        WebSocketConnection tmp = new WebSocketConnection(host, port, true);
        tmp.setSSLKeystore(certmanager.sslKeystore);
        conn = tmp;
    } else {
        conn = new PlainConnection(host, port);
    }
    conn.addConnectionHandler(this);
    connection = new RelayConnection(conn, pass);
    connection.connect();
    return true;
}

From source file:me.myatminsoe.myansms.SmsReceiver.java

/**
 * Update failed message notification./*from   ww  w  .  jav a  2s . c o  m*/
 *
 * @param context {@link Context}
 * @param uri     {@link Uri} to message
 */
private static void updateFailedNotification(final Context context, final Uri uri) {
    final Cursor c = context.getContentResolver().query(uri, Message.PROJECTION_SMS, null, null, null);
    if (c != null && c.moveToFirst()) {
        final int id = c.getInt(Message.INDEX_ID);
        final int tid = c.getInt(Message.INDEX_THREADID);
        final String body = c.getString(Message.INDEX_BODY);
        final long date = c.getLong(Message.INDEX_DATE);

        Conversation conv = Conversation.getConversation(context, tid, true);

        final NotificationManager mNotificationMgr = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
        final boolean privateNotification = p.getBoolean(PreferencesActivity.PREFS_NOTIFICATION_PRIVACY, false);
        Intent intent;
        if (conv == null) {
            intent = new Intent(Intent.ACTION_VIEW, null, context, SenderActivity.class);
        } else {
            intent = new Intent(Intent.ACTION_VIEW, conv.getUri(), context, MessageListActivity.class);
        }
        intent.putExtra(Intent.EXTRA_TEXT, body);

        String title = context.getString(R.string.error_sending_failed);

        final int[] ledFlash = PreferencesActivity.getLEDflash(context);
        final NotificationCompat.Builder b = new NotificationCompat.Builder(context)
                .setSmallIcon(android.R.drawable.stat_sys_warning).setTicker(title).setWhen(date)
                .setAutoCancel(true).setLights(RED, ledFlash[0], ledFlash[1]).setContentIntent(
                        PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
        String text;
        if (privateNotification) {
            title += "!";
            text = "";
        } else if (conv == null) {
            title += "!";
            text = body;
        } else {
            title += ": " + conv.getContact().getDisplayName();
            text = body;
        }
        b.setContentTitle(title);
        b.setContentText(text);
        final String s = p.getString(PreferencesActivity.PREFS_SOUND, null);
        if (!TextUtils.isEmpty(s)) {
            b.setSound(Uri.parse(s));
        }
        final boolean vibrate = p.getBoolean(PreferencesActivity.PREFS_VIBRATE, false);
        if (vibrate) {
            final long[] pattern = PreferencesActivity.getVibratorPattern(context);
            if (pattern.length > 1) {
                b.setVibrate(pattern);
            }
        }

        mNotificationMgr.notify(id, b.build());
    }
    if (c != null && !c.isClosed()) {
        c.close();
    }
}

From source file:com.saarang.samples.apps.iosched.service.SessionAlarmService.java

private void notifySession(final long sessionStart, final long alarmOffset) {
    long currentTime = UIUtils.getCurrentTime(this);
    final long intervalEnd = sessionStart + MILLI_TEN_MINUTES;
    LogUtils.LOGD(TAG, "Considering notifying for time interval.");
    LogUtils.LOGD(TAG, "    Interval start: " + sessionStart + "=" + (new Date(sessionStart)).toString());
    LogUtils.LOGD(TAG, "    Interval end: " + intervalEnd + "=" + (new Date(intervalEnd)).toString());
    LogUtils.LOGD(TAG, "    Current time is: " + currentTime + "=" + (new Date(currentTime)).toString());
    if (sessionStart < currentTime) {
        LogUtils.LOGD(TAG, "Skipping session notification (too late -- time interval already started)");
        return;//from w w w .j  a v  a  2  s .c  o m
    }

    if (!PrefUtils.shouldShowSessionReminders(this)) {
        // skip if disabled in settings
        LogUtils.LOGD(TAG, "Skipping session notification for sessions. Disabled in settings.");
        return;
    }

    // Avoid repeated notifications.
    if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this,
            ScheduleContract.Blocks.generateBlockId(sessionStart, intervalEnd))) {
        LogUtils.LOGD(TAG, "Skipping session notification (already notified)");
        return;
    }

    final ContentResolver cr = getContentResolver();

    LogUtils.LOGD(TAG, "Looking for sessions in interval " + sessionStart + " - " + intervalEnd);
    Cursor c = cr.query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, SessionDetailQuery.PROJECTION,
            ScheduleContract.Sessions.STARTING_AT_TIME_INTERVAL_SELECTION,
            ScheduleContract.Sessions.buildAtTimeIntervalArgs(sessionStart, intervalEnd), null);
    int starredCount = c.getCount();
    LogUtils.LOGD(TAG, "# starred sessions in that interval: " + c.getCount());
    String singleSessionId = null;
    String singleSessionRoomId = null;
    ArrayList<String> starredSessionTitles = new ArrayList<String>();
    while (c.moveToNext()) {
        singleSessionId = c.getString(SessionDetailQuery.SESSION_ID);
        singleSessionRoomId = c.getString(SessionDetailQuery.ROOM_ID);
        starredSessionTitles.add(c.getString(SessionDetailQuery.SESSION_TITLE));
        LogUtils.LOGD(TAG, "-> Title: " + c.getString(SessionDetailQuery.SESSION_TITLE));
    }
    if (starredCount < 1) {
        return;
    }

    // Generates the pending intent which gets fired when the user taps on the notification.
    // NOTE: Use TaskStackBuilder to comply with Android's design guidelines
    // related to navigation from notifications.
    Intent baseIntent = new Intent(this, MyScheduleActivity.class);
    baseIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    TaskStackBuilder taskBuilder = TaskStackBuilder.create(this).addNextIntent(baseIntent);

    // For a single session, tapping the notification should open the session details (b/15350787)
    if (starredCount == 1) {
        taskBuilder.addNextIntent(
                new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri(singleSessionId)));
    }

    PendingIntent pi = taskBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);

    final Resources res = getResources();
    String contentText;
    int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000;
    if (minutesLeft < 1) {
        minutesLeft = 1;
    }

    if (starredCount == 1) {
        contentText = res.getString(com.saarang.samples.apps.iosched.R.string.session_notification_text_1,
                minutesLeft);
    } else {
        contentText = res.getQuantityString(
                com.saarang.samples.apps.iosched.R.plurals.session_notification_text, starredCount - 1,
                minutesLeft, starredCount - 1);
    }

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText)
            .setColor(getResources().getColor(com.saarang.samples.apps.iosched.R.color.theme_primary))
            .setTicker(res
                    .getQuantityString(com.saarang.samples.apps.iosched.R.plurals.session_notification_ticker,
                            starredCount, starredCount))
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS,
                    SessionAlarmService.NOTIFICATION_LED_OFF_MS)
            .setSmallIcon(com.saarang.samples.apps.iosched.R.drawable.ic_stat_notification).setContentIntent(pi)
            .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true);
    if (minutesLeft > 5) {
        notifBuilder.addAction(com.saarang.samples.apps.iosched.R.drawable.ic_alarm_holo_dark,
                String.format(res.getString(com.saarang.samples.apps.iosched.R.string.snooze_x_min), 5),
                createSnoozeIntent(sessionStart, intervalEnd, 5));
    }
    if (starredCount == 1 && PrefUtils.isAttendeeAtVenue(this)) {
        notifBuilder.addAction(com.saarang.samples.apps.iosched.R.drawable.ic_map_holo_dark,
                res.getString(com.saarang.samples.apps.iosched.R.string.title_map),
                createRoomMapIntent(singleSessionRoomId));
    }
    String bigContentTitle;
    if (starredCount == 1 && starredSessionTitles.size() > 0) {
        bigContentTitle = starredSessionTitles.get(0);
    } else {
        bigContentTitle = res.getQuantityString(
                com.saarang.samples.apps.iosched.R.plurals.session_notification_title, starredCount,
                minutesLeft, starredCount);
    }
    NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder)
            .setBigContentTitle(bigContentTitle);

    // Adds starred sessions starting at this time block to the notification.
    for (int i = 0; i < starredCount; i++) {
        richNotification.addLine(starredSessionTitles.get(i));
    }
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    LogUtils.LOGD(TAG, "Now showing notification.");
    nm.notify(NOTIFICATION_ID, richNotification.build());
}

From source file:com.notalenthack.blaster.CommandActivity.java

private void cancelStatusUpdate() {
    // Setup expiration if we never get a message from the service
    AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent();
    intent.setAction(Constants.ACTION_REFRESH_STATUS);
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    am.cancel(pi);//from  w  ww .  j a  va  2 s . c om
}