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.dslr.dashboard.PtpService.java

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

From source file:org.interactiverobotics.headset_launcher.LauncherService.java

/**
 *   ?   .//from w  w w. ja v a 2 s . c o m
 *
 */
private void cancelNotificationAndLocks() {

    // ? 

    final NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.cancel(1);

    // ?  ?

    if (mWakeLock != null) {

        mWakeLock.release();

        mWakeLock = null;
    }

    if (mKeyguardLock != null) {

        mKeyguardLock.reenableKeyguard();

        mKeyguardLock = null;
    }

    //    ?

    stopSelf();
}

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

private void cancelNotification() {
    if (mCurrentConversationManager.getCurrentConversation() == null)
        return;/*  w w  w . ja  va  2  s.  c o  m*/
    NotificationManager notificationManager = (NotificationManager) mActivityDelegate.getActivity()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(mCurrentConversationManager.getCurrentConversation().getId().hashCode());
}

From source file:de.azapps.mirakel.services.NotificationService.java

/**
 * Updates the Notification//from  w w  w  . ja  v a 2 s.  c  o  m
 */
public void notifier() {
    if (!MirakelCommonPreferences.useNotifications() && !this.existsNotification) {
        return;
    }

    final Optional<ListMirakel> showList = ListMirakel.get(MirakelCommonPreferences.getNotificationsListId());
    Optional<ListMirakel> openList = ListMirakel.get(MirakelCommonPreferences.getNotificationsListOpenId());
    if (!showList.isPresent()) {
        return;
    }
    if (!openList.isPresent()) {
        openList = showList;
    }

    // Set onClick Intent
    final Optional<Class<?>> main = Helpers.getMainActivity();
    if (!main.isPresent()) {
        return;
    }
    final Intent openIntent = new Intent(this, main.get());
    openIntent.setAction(DefinitionsHelper.SHOW_LIST);
    openIntent.putExtra(DefinitionsHelper.EXTRA_LIST, openList.get());
    openIntent.setData(Uri.parse(openIntent.toUri(Intent.URI_INTENT_SCHEME)));
    final PendingIntent pOpenIntent = PendingIntent.getActivity(this, 0, openIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final List<Task> todayTasks = showList.get().tasks(false);
    final String notificationTitle;
    final String notificationText;
    if (todayTasks.isEmpty()) {
        notificationTitle = getString(R.string.notification_title_empty);
        notificationText = "";
    } else {
        if (todayTasks.size() == 1) {
            notificationTitle = getString(R.string.notification_title_general_single, showList.get().getName());
        } else {
            notificationTitle = String.format(getString(R.string.notification_title_general), todayTasks.size(),
                    showList.get().getName());
        }
        notificationText = todayTasks.get(0).getName();
    }
    final boolean persistent = MirakelCommonPreferences.usePersistentNotifications();
    // Build notification
    final NotificationCompat.Builder noti = new NotificationCompat.Builder(this)
            .setContentTitle(notificationTitle).setContentText(notificationText)
            .setSmallIcon(R.drawable.ic_mirakel)
            .setLargeIcon(Helpers.getBitmap(R.drawable.mirakel, getBaseContext())).setContentIntent(pOpenIntent)
            .setOngoing(persistent);
    // Big View
    if ((todayTasks.size() > 1) && (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN)) {
        final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        for (final Task task : todayTasks) {
            inboxStyle.addLine(task.getName());
        }
        noti.setStyle(inboxStyle);
    }
    final NotificationManager notificationManager = (NotificationManager) getSystemService(
            NOTIFICATION_SERVICE);
    notificationManager.notify(DefinitionsHelper.NOTIF_DEFAULT, noti.build());
    if ((todayTasks.isEmpty()) || !MirakelCommonPreferences.useNotifications()) {
        notificationManager.cancel(DefinitionsHelper.NOTIF_DEFAULT);
        this.existsNotification = false;
    } else {
        this.existsNotification = true;
    }
}

From source file:org.y20k.transistor.PlayerService.java

@Override
public void onDestroy() {
    super.onDestroy();

    // save state
    mPlayback = false;/*from   w ww .ja  va2  s.c o m*/
    savePlaybackState();

    // unregister receivers
    this.unregisterReceiver(mHeadphoneUnplugReceiver);

    // retrieve notification system service and cancel notification
    NotificationManager notificationManager = (NotificationManager) getApplication()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(PLAYER_SERVICE_NOTIFICATION_ID);

}

From source file:com.licenta.android.licenseapp.activity.MainTabActivity.java

private void handleNotificationAction(int notificationId) {
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    switch (notificationId) {
    case Constants.PANIC_ID:

        notificationManager.cancel(notificationId);
        break;//  ww w .j a va  2 s.com
    case Constants.ALARM_ID:
        if (getIntent().getBooleanExtra(Constants.KEY_DISMISS_ALARM, false)) {
            showPinDialog(true);
            //AlarmReceiver.cancelAlarm(this);
        } else {

        }

        notificationManager.cancel(notificationId);
        break;
    }
}

From source file:org.y20k.transistor.PlayerService.java

private void stopPlayback() {
    // release player
    releaseMediaPlayer();//  w  w w .  ja v a  2s  .  com

    // save state
    mPlayback = false;
    savePlaybackState();

    // send local broadcast (needed by PlayerActivityFragment and MainActivityFragment)
    Intent i = new Intent();
    i.setAction(ACTION_PLAYBACK_STOPPED);
    LocalBroadcastManager.getInstance(this.getApplication()).sendBroadcast(i);

    // retrieve notification system service and cancel notification
    NotificationManager notificationManager = (NotificationManager) getApplication()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(PLAYER_SERVICE_NOTIFICATION_ID);
}

From source file:com.example.android.pingme.PingService.java

@Override
protected void onHandleIntent(Intent intent) {
    // The reminder message the user set.
    mMessage = intent.getStringExtra(CommonConstants.EXTRA_MESSAGE);
    // The timer duration the user set. The default is 10 seconds.
    mMillis = intent.getIntExtra(CommonConstants.EXTRA_TIMER, CommonConstants.DEFAULT_TIMER_DURATION);
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    String action = intent.getAction();
    // This section handles the 3 possible actions:
    // ping, snooze, and dismiss.
    if (action.equals(CommonConstants.ACTION_PING)) {
        issueNotification(intent, mMessage);
    } else if (action.equals(CommonConstants.ACTION_SNOOZE)) {
        nm.cancel(CommonConstants.NOTIFICATION_ID);
        Log.d(CommonConstants.DEBUG_TAG, getString(R.string.snoozing));
        // Sets a snooze-specific "done snoozing" message.
        issueNotification(intent, getString(R.string.done_snoozing));

    } else if (action.equals(CommonConstants.ACTION_DISMISS)) {
        nm.cancel(CommonConstants.NOTIFICATION_ID);
    }/*from w  w  w . j av a  2 s  . c o m*/
}

From source file:org.ciasaboark.tacere.manager.NotificationManagerWrapper.java

public void displayQuickSilenceNotification(int quicksilenceDurationMinutes) {
    BetaPrefs betaPrefs = new BetaPrefs(context);
    if (betaPrefs.getDisableNotifications()) {
        Log.d(TAG, "asked to display quicksilence notification, but this has been disabled in "
                + "beta settings. Stopping any ongoing notifications");
        cancelAllNotifications();//from   w  w w .  j  a  v a2 s.  c  o m
    } else {
        // the intent attached to the notification should only cancel the quick silence request, but
        // not launch the app
        Intent notificationIntent = new Intent(context, EventSilencerService.class);
        notificationIntent.putExtra(EventSilencerService.WAKE_REASON, RequestTypes.CANCEL_QUICKSILENCE.value);
        long endTime = System.currentTimeMillis()
                + (long) quicksilenceDurationMinutes * EventInstance.MILLISECONDS_IN_MINUTE;

        DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
        Date date = new Date(endTime);
        String formattedDate = dateFormat.format(date);
        String formattedString = String
                .format(context.getString(R.string.notification_quicksilence_description), formattedDate);

        // FLAG_CANCEL_CURRENT is required to make sure that the extras are including in the new
        // pending intent
        PendingIntent pendIntent = PendingIntent.getService(context, REQUEST_CODES.QUICKSILENCE_CANCEL,
                notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        //an intent to open the main app
        Intent openMainIntent = new Intent(context, MainActivity.class);
        openMainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        openMainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent openMainPendIntent = PendingIntent.getActivity(context,
                REQUEST_CODES.QUICKSILENCE_OPEN_MAIN, openMainIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        //An additional button to extend the quicksilence by 15min
        // this intent will be attached to the button on the notification
        Intent addMinutesIntent = new Intent(context, ExtendQuicksilenceService.class);
        addMinutesIntent.putExtra(ExtendQuicksilenceService.ORIGINAL_END_TIMESTAMP, endTime);
        addMinutesIntent.putExtra(ExtendQuicksilenceService.EXTEND_LENGTH, 15);
        PendingIntent addMinPendIntent = PendingIntent.getService(context, REQUEST_CODES.QUICKSILENCE_ADD_TIME,
                addMinutesIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(context)
                .setContentTitle(context.getString(R.string.notification_quicksilence_title))
                .setContentText(formattedString)
                .setTicker(context.getString(R.string.notification_quicksilence_ticker))
                .setSmallIcon(R.drawable.not_silence).setAutoCancel(true).setOngoing(true)
                .setContentIntent(pendIntent).setColor(context.getResources().getColor(R.color.accent))
                .setTicker(context.getString(R.string.notification_quicksilence_ticker));

        notBuilder.addAction(R.drawable.app_mono_small, "Open Tacere", openMainPendIntent);
        //the +15 button should only be available in the Pro version
        Authenticator authenticator = new Authenticator(context);
        if (authenticator.isAuthenticated()) {
            notBuilder.addAction(R.drawable.not_clock, "+15", addMinPendIntent);
        }

        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(NOTIFICATION_ID);
        nm.notify(NOTIFICATION_ID, notBuilder.build());
    }
}

From source file:com.stanleyidesis.quotograph.api.controller.LWQNotificationControllerImpl.java

@Override
public void dismissNewWallpaperNotification() {
    NotificationManager notificationManager = (NotificationManager) LWQApplication.get()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(NOTIF_ID_PRIMARY);
}