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.jitsi.impl.androidtray.AndroidPopup.java

/**
 * Removes this notification./* w w  w  . j ava 2  s  .com*/
 */
public void removeNotification() {
    cancelTimeout();

    NotificationManager notifyManager = JitsiApplication.getNotificationManager();
    notifyManager.cancel(id);
}

From source file:org.jraf.android.bikey.app.collect.LogCollectorService.java

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

From source file:com.jwork.spycamera.CameraTaskService.java

@Override
public void onDestroy() {
    log.v(this, "onDestroy()");
    super.onDestroy();
    running = false;/*w  w w.  j  a  va 2s  .co m*/
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(NOTIFICATION_ID);

    if (state == WHAT_START_AUTOSHOT) {
        Message backMsg = Message.obtain();
        backMsg.what = MainController.WHAT_STOP_AUTOSHOOT;
        try {
            outMessenger.send(backMsg);
        } catch (android.os.RemoteException e1) {
            log.w(this, e1);
        }
    } else if (state == WHAT_START_VIDEO_RECORDING) {
        Message backMsg = Message.obtain();
        backMsg.what = MainController.WHAT_STOP_VIDEO;
        try {
            outMessenger.send(backMsg);
        } catch (android.os.RemoteException e1) {
            log.w(this, e1);
        }
    } else if (state == WHAT_START_FACESHOT) {
        Message backMsg = Message.obtain();
        backMsg.what = MainController.WHAT_STOP_FACESHOOT;
        try {
            outMessenger.send(backMsg);
        } catch (android.os.RemoteException e1) {
            log.w(this, e1);
        }
    }

    setState(WHAT_STOP);
}

From source file:org.jraf.android.dcn.handheld.app.geofencing.GeofencingService.java

private void dismissNotification() {
    Log.d();/*w  w  w.j av a2  s .  c o m*/
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(NOTIFICATION_ID);

    // Dismiss Wear notification
    // Blocking
    mWearHelper.connect(this);
    mWearHelper.removeNotification();
}

From source file:net.xisberto.work_schedule.alarm.AlarmMessageActivity.java

private void dismissNotification() {
    NotificationManager nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(period_pref_id);
}

From source file:org.apps8os.motivator.ui.MoodQuestionActivity.java

/** Called when the activity is first created. */
@Override/* w  w  w.j a  v a  2 s  . com*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mood_question);
    mDayDataHandler = new DayDataHandler(this);

    mCardsViewPagerEnergy = (ViewPager) findViewById(R.id.mood_question_viewpager_cards);
    mCardsViewPagerEnergy.setAdapter(new ImagesPagerAdapter(mImages1, mTitles1, this));

    setViewPager(mCardsViewPagerEnergy);

    mEnergyLevelText = (TextView) findViewById(R.id.mood_question_energylevel_textview);
    mEnergyLevelText.setText(mCardsViewPagerEnergy.getAdapter().getPageTitle(DEFAULT_MOOD_SELECTION));

    // Set an OnPageChangeListener to the ViewPager, change the text when a page is selected
    mCardsViewPagerEnergy
            .setOnPageChangeListener(new ViewPageChangeListener(mCardsViewPagerEnergy, mEnergyLevelText));

    mCardsViewPagerMood = (ViewPager) findViewById(R.id.mood_question_viewpager_cards2);
    mCardsViewPagerMood.setAdapter(new ImagesPagerAdapter(mImages2, mTitles2, this));

    setViewPager(mCardsViewPagerMood);

    // Get the text field for energy level
    mMoodLevelText = (TextView) findViewById(R.id.mood_question_moodlevel_textview);
    mMoodLevelText.setText(mCardsViewPagerMood.getAdapter().getPageTitle(DEFAULT_MOOD_SELECTION));

    // Set an OnPageChangeListener to the ViewPager, change the text when a page is selected
    mCardsViewPagerMood
            .setOnPageChangeListener(new ViewPageChangeListener(mCardsViewPagerMood, mMoodLevelText));
    final LayoutInflater inflater = getLayoutInflater();
    LinearLayout buttons = (LinearLayout) findViewById(R.id.mood_question_buttons);

    // Change the OK button to next button which opens the checking events activity if there are events to check.
    final Bundle extras = getIntent().getExtras();
    if (extras != null && extras.getBoolean(EventDataHandler.EVENTS_TO_CHECK, false)) {
        Button nextButton = (Button) inflater.inflate(R.layout.element_ok_button, buttons, false);
        nextButton.setText(getString(R.string.next));
        nextButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                saveMood(v);
                Intent intent = new Intent(MoodQuestionActivity.this, CheckEventsActivity.class);
                intent.putExtra(MotivatorEvent.YESTERDAYS_EVENTS,
                        extras.getParcelableArrayList(MotivatorEvent.YESTERDAYS_EVENTS));
                startActivity(intent);
                NotificationManager notificationManager = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                notificationManager.cancel(NotificationService.NOTIFICATION_ID_MOOD);
                finish();
            }

        });
        buttons.addView(nextButton);
    } else {

        Button okButton = (Button) inflater.inflate(R.layout.element_ok_button, buttons, false);
        okButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                saveMood(v);

                String toastMsg;
                if (mCardsViewPagerMood.getCurrentItem() > 2) {
                    toastMsg = getString(R.string.questionnaire_done_toast_good_mood);
                } else if (mCardsViewPagerMood.getCurrentItem() == 2) {
                    toastMsg = getString(R.string.questionnaire_done_toast_ok_mood);
                } else {
                    toastMsg = getString(R.string.questionnaire_done_toast_bad_mood);
                }
                View toastLayout = (View) inflater.inflate(R.layout.element_mood_toast,
                        (ViewGroup) findViewById(R.id.mood_toast_layout));
                TextView toastText = (TextView) toastLayout.findViewById(R.id.mood_toast_text);
                toastText.setText(toastMsg);
                toastText.setTextColor(Color.WHITE);

                Toast questionnaireDone = new Toast(getApplicationContext());
                questionnaireDone.setDuration(Toast.LENGTH_SHORT);
                questionnaireDone.setView(toastLayout);
                questionnaireDone.show();

                NotificationManager notificationManager = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                notificationManager.cancel(NotificationService.NOTIFICATION_ID_MOOD);

                finish();
            }

        });
        buttons.addView(okButton);
    }
}

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

/**
 * Clear a specific notification without canceling repeating alarms
 * /*from   ww w . ja  v a2  s .c  o m*/
 * @param notificationID
 *            The original ID of the notification that was used when it was
 *            registered using add()
 */
public void clear(String notificationId) {
    SharedPreferences settings = getSharedPreferences();
    Map<String, ?> alarms = settings.getAll();
    NotificationManager nc = getNotificationManager();

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

    JSONObject arguments;
    try {
        arguments = new JSONObject(alarms.get(notificationId).toString());
        Options options = new Options(context).parse(arguments);
        Date now = new Date();
        if ((options.getInterval() != 0)) {
            persist(notificationId, setInitDate(arguments));
        } else if ((new Date(options.getDate()).before(now))) {
            unpersist(notificationId);
        }
    } catch (JSONException e) {
        unpersist(notificationId);
        e.printStackTrace();
        return;
    }
}

From source file:ch.carteggio.provider.sync.NotificationService.java

private void hideFailureNotification() {

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    mNotificationManager.cancel(ERROR_NOTIFICATION_ID);
}

From source file:de.geeksfactory.opacclient.reminder.ReminderCheckService.java

@Override
public int onStartCommand(Intent intent, int flags, int startid) {
    if (ACTION_SNOOZE.equals(intent.getAction())) {
        Intent i = new Intent(ReminderCheckService.this, ReminderAlarmReceiver.class);
        PendingIntent sender = PendingIntent.getBroadcast(ReminderCheckService.this,
                OpacClient.BROADCAST_REMINDER, i, PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

        Log.i("ReminderCheckService", "Opac App Service: Quick repeat");
        // Run again in 1 day
        am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (1000 * 3600 * 24), sender);

        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.cancel(OpacClient.NOTIF_ID);
    } else {/*from   w w w  .  j  a  v a 2 s . c  om*/
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ReminderCheckService.this);
        notification_on = sp.getBoolean("notification_service", false);
        long waittime = (1000 * 3600 * 5);
        boolean executed = false;

        ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if (networkInfo != null) {
            if (!sp.getBoolean("notification_service_wifionly", false)
                    || networkInfo.getType() == ConnectivityManager.TYPE_WIFI
                    || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
                executed = true;
                new CheckTask().execute();
            } else {
                waittime = (1000 * 1800);
            }
        } else {
            waittime = (1000 * 1800);
        }

        if (!notification_on) {
            waittime = (1000 * 3600 * 12);
        }

        Intent i = new Intent(ReminderCheckService.this, ReminderAlarmReceiver.class);
        PendingIntent sender = PendingIntent.getBroadcast(ReminderCheckService.this,
                OpacClient.BROADCAST_REMINDER, i, PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + waittime, sender);

        if (!executed) {
            stopSelf();
        }
    }

    return START_NOT_STICKY;
}

From source file:com.PrivacyGuard.Application.Network.FakeVPN.MyVpnService.java

public void deleteNotification(int id) {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    mNotificationManager.cancel(id);
}