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.sbhstimetable.sbhs_timetable_android.backend.service.NotificationService.java

/**
 * Handle action Baz in the provided background thread with the provided
 * parameters./*www. ja v  a 2s  .c  om*/
 */
private void handleNotificationUpdate() {
    NotificationManager m = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("notifications_enable", false)) {
        // only show a notification if it's configured
        m.cancel(NOTIFICATION_NEXT);
        return;
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.mipmap.ic_launcher);
    if (BelltimesJson.getInstance() == null)
        return;
    BelltimesJson.Bell next = BelltimesJson.getInstance().getNextBell();
    if (next == null) {
        // Show tomorrow. TODO
        m.cancel(NOTIFICATION_NEXT);
        return;
    }
    String title = next.getLabel();
    Integer[] b = next.getBell();
    b[0] = b[0] % 12;
    if (b[0] == 0)
        b[0] = 12;
    String subText = "at " + String.format("%02d:%02d", b);
    subText += (next.getBell()[0] >= 12 ? "pm" : "am");
    if (next.isPeriod() && TodayJson.getInstance() != null) {
        TodayJson.Period p = TodayJson.getInstance().getPeriod(next.getPeriodNumber());
        title = p.name() + " in " + p.room();
        subText += " with " + p.teacher();
    }
    builder.setContentTitle(title);
    builder.setContentText(subText);
    if (DateTimeHelper.milliSecondsUntilNextEvent() < 0) {
        Log.e("notificationService", "an event in the past? bailing out...");
        return;
    }
    Log.i("notificationService", "updating. time until next event: "
            + DateTimeHelper.formatToCountdown(DateTimeHelper.milliSecondsUntilNextEvent()));

    ScheduledExecutorService ses = new ScheduledThreadPoolExecutor(1);
    m.notify(NOTIFICATION_NEXT, builder.build());
    ses.schedule(new NotificationRunner(this), DateTimeHelper.milliSecondsUntilNextEvent(),
            TimeUnit.MILLISECONDS);
}

From source file:org.chirpradio.mobile.PlaybackService.java

private void cancelNotification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    mNotificationManager.cancel(CHIRP_ID);
}

From source file:com.samknows.measurement.test.TestExecutor.java

public void cancelNotification() {
    NotificationManager manager = (NotificationManager) tc.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.cancel(Constants.NOTIFICATION_ID);
}

From source file:com.apotheosis.acceleration.monitor.MainMenuActivity.java

private void stopCollection() {
    if (collector != null) {
        collector.stop();/*from www.j a  va  2s  .  c o  m*/
        collector = null;
        pauseAccel.setText("Start");

        if (getSupportActionBar() != null)
            getSupportActionBar().setTitle("Data Collection Not Running");
    }

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(R.string.app_name);

    ListView lv = (ListView) findViewById(R.id.fileList);
    ((FileListAdapter) lv.getAdapter()).refreshFiles();
}

From source file:com.frostwire.android.gui.NotificationUpdateDemon.java

private void updatePermanentStatusNotification() {
    if (!ConfigurationManager.instance()
            .getBoolean(Constants.PREF_KEY_GUI_ENABLE_PERMANENT_STATUS_NOTIFICATION)) {
        return;//from   ww  w.j a  va2s.  c om
    }

    if (notificationViews == null || notificationObject == null) {
        LOG.warn("Notification views or object are null, review your logic");
        return;
    }

    // number of uploads (seeding) and downloads
    TransferManager transferManager;

    try {
        transferManager = TransferManager.instance();
    } catch (IllegalStateException btEngineNotReadyException) {
        return;
    }

    if (transferManager != null) {
        int downloads = transferManager.getActiveDownloads();
        int uploads = transferManager.getActiveUploads();
        if (downloads == 0 && uploads == 0) {
            NotificationManager manager = (NotificationManager) mParentContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            if (manager != null) {
                try {
                    manager.cancel(Constants.NOTIFICATION_FROSTWIRE_STATUS);
                } catch (SecurityException ignored) {
                    // possible java.lang.SecurityException
                }
            }
            return; // quick return
        }
        //  format strings
        String sDown = UIUtils.rate2speed(transferManager.getDownloadsBandwidth() / 1024);
        String sUp = UIUtils.rate2speed(transferManager.getUploadsBandwidth() / 1024);
        // Transfers status.
        notificationViews.setTextViewText(R.id.view_permanent_status_text_downloads, downloads + " @ " + sDown);
        notificationViews.setTextViewText(R.id.view_permanent_status_text_uploads, uploads + " @ " + sUp);
        final NotificationManager notificationManager = (NotificationManager) mParentContext
                .getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager != null) {
            try {
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
                    NotificationChannel channel = new NotificationChannel(
                            Constants.FROSTWIRE_NOTIFICATION_CHANNEL_ID, "FrostWire",
                            NotificationManager.IMPORTANCE_MIN);
                    channel.setSound(null, null);
                    notificationManager.createNotificationChannel(channel);
                }
                notificationManager.notify(Constants.NOTIFICATION_FROSTWIRE_STATUS, notificationObject);
            } catch (SecurityException ignored) {
                // possible java.lang.SecurityException
                ignored.printStackTrace();
            } catch (Throwable ignored2) {
                // possible android.os.TransactionTooLargeException
                ignored2.printStackTrace();
            }
        }
    }
}

From source file:de.yaacc.util.FileDownloader.java

/**
 * Cancels the notification.//  w  ww .j a  va  2s. c  o  m
 */
private void cancleNotification() {
    NotificationManager mNotificationManager = (NotificationManager) upnpClient.getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    Log.d(getClass().getName(), "Cancle Notification with ID: " + NotificationId.FILE_DOWNLOADER.getId());
    mNotificationManager.cancel(NotificationId.FILE_DOWNLOADER.getId());

}

From source file:com.yeldi.yeldibazaar.FDroid.java

public void removeNotification(int id) {
    NotificationManager nMgr = (NotificationManager) getBaseContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    nMgr.cancel(1);
}

From source file:io.github.carlorodriguez.alarmon.AlarmClockService.java

@Override
public void onDestroy() {
    super.onDestroy();
    db.closeConnections();/*www  .jav  a 2 s.  c o  m*/

    ReceiverNotificationRefresh.stopRefreshing(getApplicationContext());

    final NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.cancel(NOTIFICATION_BAR_ID);

    setSystemAlarmStringOnLockScreen(getApplicationContext(), null);
}

From source file:de.appplant.cordova.plugin.notification.NotificationWrapper.java

/**
 * Cancel existing notification//w w w. j  a va2  s  . co  m
 */
public void cancel(String notificationId) {
    /*
       * Create an intent that looks similar, to the one that was registered
       * using add. Making sure the notification id in the action is the same.
       * Now we can search for such an intent using the 'getService' method
       * and cancel it.
       */
    Intent intent = new Intent(context, receiver).setAction("" + notificationId);

    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
    AlarmManager am = getAlarmManager();
    NotificationManager nc = getNotificationManager();

    am.cancel(pi);

    try {
        nc.cancel(Integer.parseInt(notificationId));
    } catch (Exception e) {
    }
    unpersist(notificationId);
}

From source file:com.syncedsynapse.kore2.service.NotificationService.java

private void removeNotification() {
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(NOTIFICATION_ID);
}