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(String tag, int id) 

Source Link

Document

Cancel a previously shown notification.

Usage

From source file:org.mariotaku.twidere.fragment.support.HomeTimelineFragment.java

@Override
public void setUserVisibleHint(final boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    final FragmentActivity activity = getActivity();
    if (isVisibleToUser && activity != null) {
        final NotificationManager nm = (NotificationManager) activity
                .getSystemService(Context.NOTIFICATION_SERVICE);
        for (long accountId : getAccountIds()) {
            final String tag = "home_" + accountId;
            nm.cancel(tag, NOTIFICATION_ID_HOME_TIMELINE);
        }/*from w w  w  .  j  ava2  s  . co m*/
    }
}

From source file:org.mariotaku.twidere.fragment.support.MentionsTimelineFragment.java

@Override
public void setUserVisibleHint(final boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    final FragmentActivity activity = getActivity();
    if (isVisibleToUser && activity != null) {
        final NotificationManager nm = (NotificationManager) activity
                .getSystemService(Context.NOTIFICATION_SERVICE);
        for (long accountId : getAccountIds()) {
            final String tag = "mentions_" + accountId;
            nm.cancel(tag, NOTIFICATION_ID_MENTIONS_TIMELINE);
        }/*from   ww w  .j ava 2s  .  co  m*/
    }
}

From source file:com.ntsync.android.sync.activities.KeyPasswordActivity.java

private void clearNotification(String accountName) {
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(accountName, Constants.NOTIF_MISSING_KEY);
}

From source file:com.wifiafterconnect.WifiAuthenticator.java

public void cancelWatchdogNotification() {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    if (nm != null) {
        nm.cancel(WATCHDOG_NOTIFICATION_ID, 1);
        nm.cancel(WALLED_GARDEN_NOTIFICATION_ID, 1);
        nm.cancel(CAPTIVE_PORTAL_TRACKER_NOTIFICATION_ID, 1);
    }/*from w ww  . j  ava 2 s  .co  m*/
}

From source file:com.glanznig.beepme.BeeperApp.java

public void setBeeperActive(int active) {
    UptimeTable uptimeTbl = new UptimeTable(this.getApplicationContext(), timerProfile);
    getPreferences().setBeeperActive(active);

    if (active == BEEPER_ACTIVE) {
        getPreferences().setUptimeId(uptimeTbl.startUptime(Calendar.getInstance().getTime()));
        createNotification();//  w  ww.  j a  va  2s  . co  m
    } else {
        long uptimeId = getPreferences().getUptimeId();

        if (uptimeId != 0L) {
            uptimeTbl.endUptime(uptimeId, Calendar.getInstance().getTime());
            getPreferences().setUptimeId(0L);
            NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            manager.cancel(TAG, NOTIFICATION_ID);
        }
    }
}

From source file:com.glanznig.beepme.BeeperApp.java

@Override
public void onCreate() {
    super.onCreate();
    getPreferences();/*w w w .j  a v a  2s  . c  om*/
    setTimerProfile();

    onAppUpdate(getPreferences().getAppVersion());

    // save thumbnail sizes
    DisplayMetrics metrics = this.getResources().getDisplayMetrics();
    int screenDpWidth = (int) (metrics.widthPixels / metrics.density + 0.5f);
    int[] sizes = { 48, 64, screenDpWidth };
    getPreferences().setThumbnailSizes(sizes);

    // listen to call events
    if (callStateListener == null) {
        callStateListener = new CallStateListener(BeeperApp.this);
    }
    TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    telManager.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);

    //set export running to false
    getPreferences().setExportRunningSince(0L);

    UptimeTable uptimeTbl = new UptimeTable(this.getApplicationContext(), timerProfile);

    if (isBeeperActive()) {
        long scheduledBeepId = getPreferences().getScheduledBeepId();
        //is there a scheduled beep, if no, create one, if yes and it is expired, create a new one
        if (scheduledBeepId != 0L) {
            ScheduledBeepTable sbt = new ScheduledBeepTable(this.getApplicationContext());
            if (sbt.getStatus(scheduledBeepId) != 3 && sbt.isExpired(scheduledBeepId)) {
                expireTimer();
                setTimer();
            }
        } else {
            setTimer();
        }

        //is there a notification, if no, create one
        //cannot check if there is a notification or not, so call create, it will be replaced
        createNotification();

        //is there a open uptime interval, if no, create one
        long uptimeId = getPreferences().getUptimeId();
        if (uptimeId == 0L) {
            getPreferences().setUptimeId(uptimeTbl.startUptime(Calendar.getInstance().getTime()));
        }
    } else {
        long scheduledBeepId = getPreferences().getScheduledBeepId();
        //is there a scheduled beep, if yes, cancel it
        if (scheduledBeepId != 0L) {
            cancelTimer();
        }

        //cancel notifications
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        manager.cancel(TAG, NOTIFICATION_ID);
        manager.cancel(TAG, ExportActivity.EXPORT_RUNNING_NOTIFICATION);

        //is there a open uptime interval, if yes, end it
        long uptimeId = getPreferences().getUptimeId();

        if (uptimeId != 0L) {
            uptimeTbl.endUptime(uptimeId, Calendar.getInstance().getTime());
            getPreferences().setUptimeId(0L);
        }
    }
}

From source file:com.github.vseguip.sweet.contacts.SweetConflictResolveActivity.java

/**
 * // w  w w  .ja  va  2s.c o  m
 */
private void quitResolver() {
    task.cancel(true);
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.cancel(NOTIFY_CONFLICT, NOTIFY_CONTACT);
    finish();
}

From source file:org.mariotaku.twidere.fragment.support.DirectMessagesFragment.java

@Override
public void setUserVisibleHint(final boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    final FragmentActivity activity = getActivity();
    if (isVisibleToUser && activity != null) {
        final NotificationManager nm = (NotificationManager) activity
                .getSystemService(Context.NOTIFICATION_SERVICE);
        for (long accountId : getAccountIds()) {
            final String tag = "messages_" + accountId;
            nm.cancel(tag, NOTIFICATION_ID_DIRECT_MESSAGES);
        }//from   w  w w.j  a  v  a  2s.co  m
    }
}

From source file:com.metinkale.prayerapp.vakit.AlarmReceiver.java

public void fireAlarm(Intent intent) throws InterruptedException {

    Context c = App.getContext();

    if ((intent == null) || !intent.hasExtra("json")) {

        return;//from  w w  w .  j  a  va2s.  c o m
    }
    Alarm next = Alarm.fromString(intent.getStringExtra("json"));
    intent.removeExtra("json");

    if (next.city == 0) {
        return;
    }

    Times t = Times.getTimes(next.city);
    if (t == null)
        return;
    boolean active;
    if (next.cuma) {
        active = t.isCumaActive();
    } else if (next.early) {
        active = t.isEarlyNotificationActive(next.vakit);
    } else {
        active = t.isNotificationActive(next.vakit);
    }
    if (!active) {
        return;
    }

    boolean vibrate;
    String sound;
    String dua;
    long silenter;
    if (next.cuma) {
        vibrate = t.hasCumaVibration();
        sound = t.getCumaSound();
        dua = "silent";
        silenter = t.getCumaSilenterDuration();
    } else if (next.early) {
        vibrate = t.hasEarlyVibration(next.vakit);
        sound = t.getEarlySound(next.vakit);
        dua = "silent";
        silenter = t.getEarlySilenterDuration(next.vakit);
    } else {
        vibrate = t.hasVibration(next.vakit);
        sound = t.getSound(next.vakit);
        dua = t.getDua(next.vakit);
        silenter = t.getSilenterDuration(next.vakit);
    }

    NotificationManager nm = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);

    nm.cancel(next.city + "", NotIds.ALARM);
    String text;

    text = t.getName() + " (" + t.getSource() + ")";

    String txt = "";
    if (next.early) {
        String[] left_part = App.getContext().getResources().getStringArray(R.array.lefttext_part);
        txt = App.getContext().getString(R.string.earlyText, left_part[next.vakit.index],
                "" + t.getEarlyTime(next.vakit));
    } else if (next.cuma) {
        String[] left_part = App.getContext().getResources().getStringArray(R.array.lefttext_part);
        txt = App.getContext().getString(R.string.earlyText, left_part[next.vakit.index], "" + t.getCumaTime());
    } else if (next.vakit != null) {
        txt = next.vakit.getString();
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(c).setContentTitle(text)
            .setContentText(txt).setContentIntent(Main.getPendingIntent(t)).setSmallIcon(R.drawable.ic_abicon);
    Notification not = builder.build();

    if (vibrate) {
        not.vibrate = VibrationPreference.getPattern(c, "vibration");
    }

    AudioManager am = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);

    class MPHolder {
        MediaPlayer mp;
    }
    not.deleteIntent = PendingIntent.getBroadcast(c, 0, new Intent(c, Audio.class),
            PendingIntent.FLAG_UPDATE_CURRENT);

    nm.notify(next.city + "", NotIds.ALARM, not);

    final MPHolder mp = new MPHolder();

    if (Prefs.showNotificationScreen() && (sound != null) && !sound.startsWith("silent")) {
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isScreenOn()) {
            Intent i = new Intent(c, NotificationPopup.class);
            i.putExtra("city", next.city);
            i.putExtra("name", text);
            i.putExtra("vakit", txt);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            c.startActivity(i);

            Thread.sleep(1000);
        }
    }

    sInterrupt = false;
    boolean hasSound = false;
    while ((sound != null) && !sound.startsWith("silent") && !sInterrupt) {
        int volume = -2;
        hasSound = true;

        if (!sound.startsWith("silent") && !sound.startsWith("picker")) {

            if (sound.contains("$volume")) {
                volume = Integer.parseInt(sound.substring(sound.indexOf("$volume") + 7));
                sound = sound.substring(0, sound.indexOf("$volume"));
            }
            if (volume != -2) {
                int oldvalue = am.getStreamVolume(getStreamType(c));
                am.setStreamVolume(getStreamType(c), volume, 0);
                volume = oldvalue;
            }

            try {
                mp.mp = play(c, sound);
            } catch (IOException e) {
                e.printStackTrace();
                if (next.cuma) {
                    t.setCumaSound("silent");
                } else if (next.early) {
                    t.setEarlySound(next.vakit, "silent");
                } else {
                    if ("sound".equals(t.getSound(next.vakit))) {
                        t.setSound(next.vakit, "silent");
                    } else {
                        t.setDua(next.vakit, "silent");
                    }
                }
                mp.mp = null;
            }

            if (mp.mp != null) {

                mp.mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                    @Override
                    public void onCompletion(MediaPlayer mediaPlayer) {
                        if (mp.mp == null) {
                            return;
                        }
                        mp.mp.stop();
                        mp.mp.release();
                        mp.mp = null;
                    }
                });

                mp.mp.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
                    @Override
                    public void onSeekComplete(MediaPlayer mediaPlayer) {
                        if (mp.mp == null) {
                            return;
                        }
                        mp.mp.stop();
                        mp.mp.release();
                        mp.mp = null;
                    }
                });

            }

            sInterrupt = false;

            while ((mp.mp != null) && mp.mp.isPlaying()) {
                if (sInterrupt) {
                    mp.mp.stop();
                    mp.mp.release();
                    mp.mp = null;

                    dua = null;
                } else {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException ignore) {
                    }
                }
            }
            sInterrupt = false;

        }

        if (volume != -2) {
            am.setStreamVolume(getStreamType(c), volume, 0);
        }
        sound = dua;
        dua = null;
    }

    if (hasSound && Prefs.autoRemoveNotification()) {
        nm.cancel(next.city + "", NotIds.ALARM);
    }
    if (silenter != 0) {
        silenter(c, silenter);
    }

}

From source file:de.tubs.ibr.dtn.chat.service.ChatService.java

public void clearNotification(Long buddyId) {
    if (buddyId == null)
        return;/*from  w w  w.j  a  v  a2 s  .c  o  m*/

    // clear notification
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancel(buddyId.toString(), MESSAGE_NOTIFICATION);
}