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.klinker.android.twitter.services.SendQueue.java

public void finishedTweetingNotification() {
    try {/*from   ww  w .ja  v  a  2s.c  o m*/
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.sContext)
                .setSmallIcon(R.drawable.ic_stat_icon)
                .setContentTitle(getResources().getString(R.string.tweet_success)).setOngoing(false)
                .setTicker(getResources().getString(R.string.tweet_success));

        if (AppSettings.getInstance(this).vibrate) {
            Log.v("talon_vibrate", "vibrate on compose");
            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
            long[] pattern = { 0, 50, 500 };
            v.vibrate(pattern, -1);
        }

        stopForeground(true);

        NotificationManager mNotificationManager = (NotificationManager) MainActivity.sContext
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(6, mBuilder.build());
        // cancel it immediately, the ticker will just go off
        mNotificationManager.cancel(6);
    } catch (Exception e) {
        // not attached to activity
    }
}

From source file:com.vonglasow.michael.satstat.ui.SettingsActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    if ((requestCode == Const.PERM_REQUEST_MAP_DOWNLOAD) && (grantResults.length > 0)) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
            startActivity(new Intent(this, MapDownloadActivity.class));
        else {//w ww  .j  a v a2  s.c  om
            String message = getString(R.string.status_perm_map_download);
            Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
        }
    } else if ((requestCode == Const.PERM_REQUEST_LOCATION_PREF) && (grantResults.length > 0)) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            NotificationManager notificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);
            notificationManager.cancel(Const.PERM_REQUEST_LOCATION_NOTIFICATION);
        } else
            Log.i(TAG,
                    "ACCESS_FINE_LOCATION permission not granted, a notification will appear when it is needed");
    }
}

From source file:com.hollandhaptics.babyapp.BabyService.java

/**
 * @brief Clears the LED indicator./*from   w w w .  ja v a 2 s.c o  m*/
 */
private void ClearLED() {
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.cancel(0);
}

From source file:com.ucmap.dingdinghelper.services.TimingService.java

@Override
public void onDestroy() {
    super.onDestroy();
    runing_monitor = false;/* w  w  w .j  a  v a2s .c  o m*/
    if (mNotifyThread != null && mNotifyThread.isAlive()) {

        /*Thread ? ???*/
        if (!mNotifyThread.isInterrupted()) {
            mNotifyThread.interrupt();
        }
    }

    NotificationManager mNotificationManager = (NotificationManager) this
            .getSystemService(NOTIFICATION_SERVICE);
    mNotificationManager.cancel(NOTIFICATION_ID_PROGRESS_ID);
    mNotificationManager.cancel(NOTIFICATION_ID);
}

From source file:it.mb.whatshare.SendToGCMActivity.java

@SuppressWarnings("deprecation")
private void showNotification(int sharedWhat, boolean sharedViaWhatsapp) {
    String title = getString(R.string.whatshare);
    Intent onNotificationDiscarded = new Intent(this, SendToGCMActivity.class);
    PendingIntent notificationIntent = PendingIntent.getActivity(this, 0, onNotificationDiscarded, 0);
    Notification notification = null;
    int notificationIcon = sharedViaWhatsapp ? R.drawable.notification_icon
            : R.drawable.whatshare_logo_notification;
    int notificationNumber = notificationCounter.incrementAndGet();
    String content = getString(R.string.share_success, getString(sharedWhat), outboundDevice.type);
    // @formatter:off
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(notificationIcon, 0)
            .setContentTitle(title).setContentText(content).setTicker(content)
            .setContentIntent(notificationIntent)
            .setDeleteIntent(PendingIntent.getActivity(this, 0, onNotificationDiscarded, 0))
            .setNumber(notificationNumber);
    // @formatter:on
    if (Build.VERSION.SDK_INT > 15) {
        notification = buildForJellyBean(builder);
    } else {/*from w  ww . j  a v  a2  s .  c o m*/
        notification = builder.getNotification();
    }
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // cancel previous notification to clean up garbage in the status bar
    nm.cancel(notificationNumber - 1);
    nm.notify(notificationNumber, notification);
}

From source file:de.aw.awlib.AWNotification.java

/**
 * Cancelt die Notification/*from  w w w  . j  a v  a 2s .c om*/
 */
public void cancel() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nMgr = (NotificationManager) context.getSystemService(ns);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        nMgr.createNotificationChannel(mNotificationChannel);
    }
    nMgr.cancel(mNotifyID);
}

From source file:de.grundid.plusrad.recording.RecordingService.java

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

From source file:com.hang.exoplayer.PlayService.java

private void dismissNotification() {
    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    manager.cancel(ID_NOTIFICATION);
}

From source file:pylapp.smoothclicker.android.notifiers.StatusBarNotifier.java

/**
 * Removes a notification/*from   w w w. ja  v  a2s .  c  om*/
 */
public void removeNotification(NotificationTypes type) {
    Logger.d(LOG_TAG, "Remove notification: " + type);
    NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    switch (type) {
    case CLICKS_ON_GOING_BY_APP:
        nm.cancel(NOTIF_CLICK_PROCESS_ON_GOING_BY_APP);
        break;
    case CLICKS_ON_GOING_STANDALONE:
        nm.cancel(NOTIF_CLICK_PROCESS_ON_GOING_STANDALONE);
        break;
    case CLICKS_ON_GOING_BY_SERVICE:
        nm.cancel(NOTIF_CLICK_PROCESS_ON_GOING_BY_SERVICE);
        break;
    case CLICKS_STOPPED:
        nm.cancel(NOTIF_CLICK_PROCESS_STOPPED);
        break;
    case CLICKS_OVER:
        nm.cancel(NOTIF_CLICK_PROCESS_OVER);
        break;
    case WATCH_OVER:
        nm.cancel(NOTIF_WATCH_PROCESS_OVER);
        break;
    case CLICK_MADE:
        nm.cancel(NOTIF_CLICK_MADE);
        break;
    case SU_GRANTED:
        nm.cancel(NOTIF_SU_GRANTED);
        break;
    case COUNT_DOWN:
        nm.cancel(NOTIF_COUNT_DOWN);
        break;
    }
}

From source file:com.google.android.apps.paco.NotificationCreator.java

private void cancelNotification(Context context, long notificationId) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(new Long(notificationId).intValue());
}