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:org.solovyev.android.calculator.floating.FloatingCalculatorService.java

private void hideNotification() {
    final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(NOTIFICATION_ID);
}

From source file:com.snippet.app.NotificationActivity.java

public void onButton6Dismiss(final View v) {
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(6);
}

From source file:org.liberty.android.fantastischmemo.service.AnyMemoService.java

private void cancelNotification() {
    try {/*from  w ww  . jav  a2  s  .  c  om*/
        NotificationManager notificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(NOTIFICATION_ID);
    } catch (Exception e) {
    }
}

From source file:at.flack.receiver.FacebookReceiver.java

public void killNotification(Context ctx, MarkAsRead mas) {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nMgr = (NotificationManager) ctx.getSystemService(ns);
    nMgr.cancel(8);
}

From source file:cn.devit.app.ip_messenger.DownloadTask.java

@Override
protected void onPostExecute(Integer result) {
    mContext.setProgress(10000);//from w w  w. ja  v  a 2s. c o  m
    Toast.makeText(mContext, "?" + result + "", Toast.LENGTH_SHORT).show();
    NotificationManager notificationManager = (NotificationManager) mContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(noteId);

}

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

private void notificationTimer() {
    TimerTask notificationTask = new TimerTask() {
        @Override//from w w  w  . j a va2 s. c om
        public void run() {
            Gson gson = new Gson();
            Appointment[] appointments = calendarDB.getNotificationAppointments();
            Log.d(TAG, "run: amount " + appointments.length);
            previousAppointment = configUtil.getString("previous_appointment");
            if (appointments.length >= 1) {
                Appointment appointment = appointments[0];
                if (!gson.toJson(appointment).equals(previousAppointment) && isCandidate(appointment)) {
                    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                            getApplicationContext());
                    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:");
                    }
                    mBuilder.setContentText(appointment.description + " in " + appointment.location);
                    mBuilder.setAutoCancel(true);
                    mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

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

                    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                            Context.NOTIFICATION_SERVICE);
                    mNotificationManager.notify(9991, mBuilder.build());

                    previousAppointment = gson.toJson(appointment);
                    configUtil.setString("previous_appointment", previousAppointment);
                }
            } else {
                NotificationManager notifManager = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                notifManager.cancel(9991);
            }
        }
    };
    timer.schedule(notificationTask, 20000, 30 * 1000);
}

From source file:com.mattprecious.prioritysms.receiver.AlarmReceiver.java

private void handleIntent(Context context, Intent intent) {
    if (!intent.hasExtra(Intents.EXTRA_PROFILE)) {
        missingExtra(Intents.EXTRA_PROFILE);
    }/*www . j a  va 2s  .  c  o  m*/

    BaseProfile profile = intent.getParcelableExtra(Intents.EXTRA_PROFILE);
    if (Intents.ALARM_KILLED.equals(intent.getAction())) {
        boolean replaced = intent.getBooleanExtra(Intents.ALARM_REPLACED, false);
        if (!replaced) {
            // TODO: throw a notification saying it was auto-killed
            NotificationManager nm = getNotificationManager(context);
            nm.cancel(profile.getId());

            // should be caught in the activity, but you can never have too
            // many stopServices!
            context.stopService(new Intent(Intents.ACTION_ALERT));
        }

        return;
    } else if (!Intents.ACTION_ALERT.equals(intent.getAction())) {
        // Unknown intent, bail.
        return;
    }

    if (!intent.hasExtra(Intents.EXTRA_NUMBER)) {
        missingExtra(Intents.EXTRA_NUMBER);
    } else if (profile instanceof SmsProfile) {
        if (!intent.hasExtra(Intents.EXTRA_MESSAGE)) {
            missingExtra(Intents.EXTRA_MESSAGE);
        }
    }

    String number = intent.getStringExtra(Intents.EXTRA_NUMBER);
    String message = intent.getStringExtra(Intents.EXTRA_MESSAGE);

    Log.v(TAG, "Received alarm set for id=" + profile.getId());

    if (profile.getActionType() == ActionType.ALARM) {
        doAlarm(context, profile, number, message);
    } else {
        doNotify(context, profile);
    }
}

From source file:org.hansel.myAlert.ReminderService.java

@Override
public void onCreate() {
    super.onCreate();
    //obtenemos el "nmero de intentos"
    getApplicationContext().registerReceiver(alarmReceiver, new IntentFilter(CANCEL_ALARM_BROADCAST));
    int count = PreferenciasHancel.getReminderCount(getApplicationContext());
    count++;// ww w. j av  a  2s  .  c  o  m
    PreferenciasHancel.setReminderCount(getApplicationContext(), count);
    Log.v("Conteo: " + count);
    if (count >= 3) {
        //detenemos la alarma del servicio de recordatorios. y lanzamos el servicio de Tracking 
        AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        am.cancel(Util.getReminderPendingIntennt(getApplicationContext()));
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancel(NOTIFICATION_ID);
        Log.v("Servicio de Rastreo....");
        Util.inicarServicio(getApplicationContext());

        startService(new Intent(getApplicationContext(), SendPanicService.class));
        stopSelf();
    } else {
        //mandamos una alerta de notificacin
        showNotifciation();
        playSound();
        mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        Vibra();
        Handler han = new Handler();
        run = new Runnable() {

            @Override
            public void run() {
                cancelAlarm();
                stopSelf();
            }
        };
        han.postDelayed(run, 1000 * 10);

        //alarma para "regresar" en caso que el usuario no de "click" en la notificacin
        AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        long due = System.currentTimeMillis() + (60000 * 3); // 3 minutos
        Log.v("Scheduling next update at " + new Date(due));
        am.set(AlarmManager.RTC_WAKEUP, due, Util.getReminderPendingIntennt(getApplicationContext()));

    }

}

From source file:com.intuitlabs.wear.voiceandchoice.ActionReceiver.java

/**
 * {@inheritDoc}//from   w  w w  . j  a  v a  2s  .  c o m
 */
@Override
public void onReceive(final Context context, final Intent _intent) {

    /** notificationId used to issue the notification, so we can cancel the notification */
    final int notificationId = _intent.getIntExtra(Intent.EXTRA_UID, -1);

    /** The bundle that was created during the speech recognition process */
    final Bundle remoteInput = RemoteInput.getResultsFromIntent(_intent);

    /* The user's choice, either directly selected or as a speech recognition result. */
    final String reply = remoteInput != null
            ? remoteInput.getCharSequence(AndroidNotification.EXTRA_VOICE_REPLY).toString()
            : "";

    /* The integer value, associated with the command string in the original json document that was used to generate the notification */
    @SuppressWarnings("unchecked")
    final Map<String, Integer> cmdkeys = (Map<String, Integer>) ListStyle.readFromSharedPreference(context);
    final int selectedId = new PhoneticSearch<>(cmdkeys).match(reply);

    Log.v(LOG_TAG, "Selection / Speech Recognition result: " + reply);
    Log.i(LOG_TAG, "Selection / Selected ID " + selectedId);

    /* Cancel the Notification, which makes it disappear on phone and watch */
    final NotificationManager manager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    manager.cancel(notificationId);

    switch (selectedId) {
    // Purchase Turbo Tax / Go to Web Page
    case 0:
    case 4:
        final String url = context.getString(R.string.turbotax_url);
        context.startActivity(
                new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        break;

    // create a calendar Event
    case 1:
    case 5:
        final Calendar cal = Calendar.getInstance();
        cal.set(2015, 3, 15);

        final Intent intent = new Intent(Intent.ACTION_INSERT).setData(CalendarContract.Events.CONTENT_URI)
                .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, cal.getTimeInMillis())
                .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, cal.getTimeInMillis() + 60 * 60 * 1000)
                .putExtra(CalendarContract.Events.TITLE, context.getString(R.string.turbotax_title))
                .putExtra(CalendarContract.Events.DESCRIPTION, context.getString(R.string.turbotax_description))
                .putExtra(CalendarContract.Events.EVENT_LOCATION, context.getString(R.string.turbotax_location))
                .putExtra(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_BUSY)
                .putExtra(Intent.EXTRA_EMAIL, context.getString(R.string.turbotax_email))
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
        break;

    // set a reminder
    case 2:
    case 6:
        // todo, set a reminder ..
        break;

    // dismiss, do nothing
    case 3:
    case 7:
    default:
    }
}

From source file:com.antonioleiva.materialeverywhere.HomeActivity1.java

public void Notification_Vibration() {
    long[] vibrationPattern = { 0, 500, 0, 30 };
    NotificationManager notifier = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notifier.cancel(RECIPE_NOTIFICATION_ID);
    //step6//  w ww  .ja  v a 2  s. c o  m
    Notification fourthPage = new NotificationCompat.Builder(this).setContentTitle("Step 6")
            .setContentText("   ? .")
            .extend(new NotificationCompat.WearableExtender().setContentIcon(R.drawable.ic_launcher)
                    .setContentIconGravity(Gravity.CENTER))
            .build();
    NotificationCompat.WearableExtender wearableOptions = new NotificationCompat.WearableExtender()
            .setContentIcon(R.drawable.ic_launcher).setContentIconGravity(Gravity.CENTER).addPage(fourthPage);

    Notification notification1 = new NotificationCompat.Builder(this).setContentTitle("? ")
            .setContentText("?  ").setSmallIcon(R.drawable.ic_launcher)
            .setVibrate(vibrationPattern).extend(wearableOptions).build();

    NotificationManagerCompat.from(this).notify(FINISH_STEP, notification1);

}