Example usage for android.app NotificationManager cancel

List of usage examples for android.app NotificationManager cancel

Introduction

In this page you can find the example usage for android.app NotificationManager cancel.

Prototype

public void cancel(int id) 

Source Link

Document

Cancel a previously shown notification.

Usage

From source file:com.chatwing.whitelabel.managers.ChatboxModeManager.java

private void cancelNotification() {
    if (mCurrentChatBoxManager.getCurrentChatBox() == null)
        return;/*from  w  w  w. j  a  va2s. c  o  m*/
    NotificationManager notificationManager = (NotificationManager) mActivityDelegate.getActivity()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(mCurrentChatBoxManager.getCurrentChatBox().getId());
}

From source file:com.android.mms.transaction.MessagingNotification.java

public static void cancelNotification(Context context, int notificationId) {
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Log.d(TAG, "cancelNotification");
    nm.cancel(notificationId);
}

From source file:org.adblockplus.android.ProxyService.java

/**
 * Stops no traffic check and resets notification message.
 *//*from w w  w.  j  a v a2s.c  o  m*/
private void stopNoTrafficCheck() {
    if (notrafficHandler != null) {
        notrafficHandler.removeCallbacks(noTraffic);
        sendStateChangedBroadcast();
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(ONGOING_NOTIFICATION_ID, getNotification());
        notificationManager.cancel(NOTRAFFIC_NOTIFICATION_ID);
    }
    notrafficHandler = null;
}

From source file:edu.cmu.cylab.starslinger.Service.java

private void queryExchangeStatus() {
    boolean reminder = SafeSlingerPrefs.getShowSlingKeysReminder();
    boolean exchanged = false;
    boolean setupComplete = !TextUtils.isEmpty(SafeSlingerPrefs.getKeyIdString());
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) getSystemService(ns);

    // update exchanged status for older versions
    RecipientDbAdapter dbRecipient = RecipientDbAdapter.openInstance(this);
    int trustRecips = dbRecipient.getTrustedRecipientCount();
    if (trustRecips > 0) {
        SafeSlingerPrefs.setFirstExchangeComplete(true);
        exchanged = true;//from w  w w.  ja va  2  s.  co m
    }

    // if keys exist, and recipients = 0, remind user to sling keys
    if (setupComplete && !exchanged && reminder) {
        Notification n = createSlingKeysReminderNotification();
        nm.notify(HomeActivity.NOTIFY_SLINGKEYS_REMIND_ID, n);
    } else {
        nm.cancel(HomeActivity.NOTIFY_SLINGKEYS_REMIND_ID);
    }

    // show once per query only
    SafeSlingerPrefs.setShowSlingKeysReminder(false);
}

From source file:com.z3r0byte.magistify.Services.BackgroundService.java

private void appointmentNotification() {
    Appointment[] appointments = calendarDB.getNotificationAppointments();
    Log.d(TAG, "AppointmentNotifications: amount of appointments that should be shown: " + appointments.length);
    String previousAppointment = configUtil.getString("previous_appointment");
    if (appointments.length >= 1) {
        Appointment appointment = appointments[0];
        if (!mGson.toJson(appointment).equals(previousAppointment) && isCandidate(appointment)) {
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
            mBuilder.setSmallIcon(R.drawable.ic_appointment);

            if (appointment.startDate != null) {
                String time = DateUtils.formatDate(appointment.startDate, "HH:mm");
                mBuilder.setContentTitle("Volgende afspraak (" + time + ")");
            } else {
                mBuilder.setContentTitle("Volgende afspraak:");
            }/*  www . j  a va  2  s . co  m*/
            mBuilder.setContentText(appointment.description + " in " + appointment.location);
            mBuilder.setAutoCancel(true);
            mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

            Intent resultIntent = new Intent(context, AppointmentActivity.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
            stackBuilder.addParentStack(AppointmentActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);

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

            if (Build.VERSION.SDK_INT >= 26) {
                String channelId = APPOINTMENT_NOTIFICATIONCHANNEL_ID;
                CharSequence channelName = APPOINTMENT_NOTIFICATIONCHANNEL_ID;
                int importance = NotificationManager.IMPORTANCE_LOW;
                NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName,
                        importance);
                notificationChannel.enableLights(false);
                notificationChannel.enableVibration(false);
                notificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
                mNotificationManager.createNotificationChannel(notificationChannel);
                mBuilder.setChannelId(APPOINTMENT_NOTIFICATIONCHANNEL_ID);
            }
            mNotificationManager.notify(APPOINTMENT_NOTIFICATION_ID, mBuilder.build());

            previousAppointment = mGson.toJson(appointment);
            configUtil.setString("previous_appointment", previousAppointment);
        }
    } else {
        NotificationManager notifManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notifManager.cancel(APPOINTMENT_NOTIFICATION_ID);
    }
}

From source file:com.z3r0byte.magistify.Services.BackgroundService.java

private void nextAppointmentChangedNotification() {
    Appointment[] appointments = scheduleChangeDB.getNotificationAppointments();
    String previousChangedAppointment = configUtil.getString("previous_changed_appointment");
    if (appointments.length > 0) {
        Appointment appointment = appointments[0];
        if (!appointment.startDateString.equals(previousChangedAppointment)) {
            String content;//from   ww w .ja  v a  2  s .c om
            if (appointment.description != null && !appointment.description.equalsIgnoreCase("null")) {
                content = appointment.description;
            } else {
                content = "De les is uitgevallen!";
            }

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
            mBuilder.setSmallIcon(R.drawable.ic_schedule_change);

            mBuilder.setContentTitle("Let op! De volgende les is gewijzigd!");
            mBuilder.setContentText(content);
            mBuilder.setAutoCancel(true);
            mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
            mBuilder.setDefaults(Notification.DEFAULT_ALL);

            Intent resultIntent = new Intent(context, ScheduleChangeActivity.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
            stackBuilder.addParentStack(ScheduleChangeActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);

            NotificationManager mNotificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            if (Build.VERSION.SDK_INT >= 26) {
                String channelId = NEXT_APPOINTMENT_CHANGED_NOTIFICATIONCHANNEL_ID;
                CharSequence channelName = NEXT_APPOINTMENT_CHANGED_NOTIFICATIONCHANNEL_ID;
                int importance = NotificationManager.IMPORTANCE_LOW;
                NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName,
                        importance);
                notificationChannel.enableLights(true);
                notificationChannel.setLightColor(Color.RED);
                notificationChannel.enableVibration(true);
                notificationChannel.setImportance(NotificationManager.IMPORTANCE_DEFAULT);
                notificationChannel.setVibrationPattern(new long[] { 100, 200, 150 });
                mNotificationManager.createNotificationChannel(notificationChannel);
                mBuilder.setChannelId(NEXT_APPOINTMENT_CHANGED_NOTIFICATIONCHANNEL_ID);
            }
            mNotificationManager.notify(NEXT_APPOINTMENT_CHANGED_NOTIFICATION_ID, mBuilder.build());

            configUtil.setString("previous_changed_appointment", appointment.startDateString);
        }
    } else {
        NotificationManager notifManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notifManager.cancel(NEXT_APPOINTMENT_CHANGED_NOTIFICATION_ID);
    }
}

From source file:esolz.connexstudent.apprtc.ConnectActivity.java

public void fireMissedCall(final String name) {
    if (!name.equals("")) {
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_notification).setContentTitle("Connex")
                .setContentText("You have a missed call from " + name).setAutoCancel(true)
                .setSound(defaultSoundUri);
        NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(3);
        notificationManager.notify(3, notificationBuilder.build());
    }/*from   www .  jav a  2 s  .  co  m*/
}

From source file:at.flack.MainActivity.java

public void cancelNotification(Context ctx, int notifyId) {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nMgr = (NotificationManager) ctx.getSystemService(ns);
    nMgr.cancel(notifyId);
}

From source file:com.embeddedlog.LightUpDroid.alarms.AlarmNotifications.java

public static void showHighPriorityNotification(Context context, AlarmInstance instance) {
    Log.v("Displaying high priority notification for alarm instance: " + instance.mId);
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Resources resources = context.getResources();
    NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
            .setContentTitle(resources.getString(R.string.alarm_alert_predismiss_title))
            .setContentText(AlarmUtils.getAlarmText(context, instance))
            .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(true).setAutoCancel(false)
            .setPriority(NotificationCompat.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM);

    // Setup up dismiss action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance,
            AlarmInstance.DISMISSED_STATE);
    notification.addAction(android.R.drawable.ic_menu_close_clear_cancel,
            resources.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getBroadcast(context,
                    instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup content action if instance is owned by alarm
    long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId;
    Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId);
    viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX);
    viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId);
    viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    nm.cancel(instance.hashCode());
    nm.notify(instance.hashCode(), notification.build());
}

From source file:com.raceyourself.android.samsung.ProviderService.java

private void disableIcon() {
    if (!iconEnabled)
        return;/*from  w  ww.  ja  va 2  s.co  m*/
    // Gets an instance of the NotificationManager service
    NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mNotifyMgr.cancel(TETHER_NOTIFICATION_ID);
    iconEnabled = false;
}