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.fairphone.peaceofmind.PeaceOfMindBroadCastReceiver.java

/**
 * Sets the Peace of mind icon on the notification bar
 * @param putIcon if true the icon is put otherwise it is removed
 * @param wasInterrupted when true, an extra notification is sent to inform the user that Peace of mind was ended
 *//*from ww  w  .ja va2 s . c o  m*/
private void setPeaceOfMindIconInNotificationBar(boolean putIcon, boolean wasInterrupted) {

    NotificationManager manager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

    if (putIcon) {

        //just in case the user didn't clear it
        manager.cancel(PEACE_OF_MIND_INTERRUPTED_NOTIFICATION);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
                .setSmallIcon(R.drawable.peace_system_bar_icon)
                .setContentTitle(mContext.getResources().getString(R.string.app_name))
                .setContentText(mContext.getResources().getString(R.string.peace_on_notification));

        Intent resultIntent = new Intent(mContext, PeaceOfMindActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(PeaceOfMindActivity.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        builder.setContentIntent(resultPendingIntent);

        Notification notificationWhileRunnig = builder.build();
        notificationWhileRunnig.flags |= Notification.FLAG_NO_CLEAR;
        // Add notification   
        manager.notify(PEACE_OF_MIND_ON_NOTIFICATION, notificationWhileRunnig);

    } else {
        manager.cancel(PEACE_OF_MIND_ON_NOTIFICATION);

        //send a notification saying that the peace was ended 
        if (wasInterrupted) {
            NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
                    .setSmallIcon(R.drawable.peace_system_bar_icon).setAutoCancel(true)
                    .setContentTitle(mContext.getResources().getString(R.string.app_name))
                    .setContentText(mContext.getResources().getString(R.string.peace_off_notification))
                    .setTicker(mContext.getResources().getString(R.string.peace_off_notification));

            manager.notify(PEACE_OF_MIND_INTERRUPTED_NOTIFICATION, builder.build());
        }
    }
}

From source file:com.daiv.android.twitter.services.SendScheduledTweet.java

public void finishedTweetingNotification() {
    try {// w  w  w  . j a  v a2s . co  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(TAG + "Test_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.elixsr.portforwarder.forwarding.ForwardingService.java

private void hideForwardingEnabledNotification() {

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    mNotificationManager.cancel(NOTIFICATION_ID);
}

From source file:de.ribeiro.android.gso.activities.PlanActivity.java

@SuppressLint("NewApi")
@Override//ww w  .  ja  va2 s .co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ImageButton FAB;
    // Android Version prfen, wenn neuer als API11,
    Boolean actionBarAvailable = false;
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        // ActionBar anfragen
        actionBarAvailable = getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    }
    _logger = new Logger(this, "PlanActivity");
    setContentView(R.layout.activity_plan);
    this.ctxt = new MyContext(this, this);

    Configuration c = getResources().getConfiguration();
    this.orientation = c.orientation;
    _logger.Info("Creating PlanActivity with orientation int: " + orientation);
    try {
        File f = new File(this.getCacheDir(), "date.bin");
        if (f.exists() && f.canRead()) {
            ctxt.mProfil.stupid.currentDate = (Calendar) FileOPs.loadObject(f);
            f.delete();
        }
    } catch (Exception e) {
        _logger.Error("An Error occurred while loading date.bin file", e);
    }

    ctxt.mProfil = new ProfilManager(ctxt).getCurrentProfil();
    ctxt.mProfil.setPrefs();
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    lbm.registerReceiver(mMessageReceiver, new IntentFilter(Const.BROADCASTREFRESH));
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        int noticationId = extras.getInt("notificationId");

        if (noticationId != 0) {
            extras.remove("notificationId");
            //notication aus taskbar entfernen
            NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            nm.cancel(noticationId);
            Calendar date = new GregorianCalendar();
            date.setTimeInMillis(extras.getLong("date"));

            extras.remove("weekIndex");
            int profilIndex = extras.getInt("profilIndex");
            extras.remove("profilIndex");

            //alle Profile laden
            ProfilManager pm = new ProfilManager(ctxt);
            if (pm.profiles.size() >= pm.currentProfilIndex) {
                pm.profiles.get(pm.currentProfilIndex).setPrefs();
                if (profilIndex > pm.profiles.size() - 1)
                    profilIndex = 0;
                else
                    pm.currentProfilIndex = profilIndex;
                pm.applyProfilIndex();
                ctxt.mProfil.loadPrefs();
            }

            ctxt.mProfil.stupid.currentDate = date;

        }

        ctxt.newVersionReqSetup = extras.getBoolean("newVersionInfo", false);
    }

    ActionBar actionBar = getActionBar();
    if (ctxt.mIsRunning)
        actionBar.show();

    ctxt.executor.post(new PlanActivityLuncher(PlanActivity.this));

    //        FAB = (ImageButton) findViewById(R.id.imageButton);
    //        FAB.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View v) {
    //                ctxt.getCurStupid().currentDate = new GregorianCalendar();
    //                ctxt.pager.setPage(ctxt.getCurStupid().currentDate);
    //            }
    //        });
}

From source file:com.bubblegum.traceratops.app.service.LoggerService.java

private void hidePersistentNotification() {
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.cancel(R.id.traceratops_running_id);
}

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

/**
 * Cancel any ongoing notifications, this will remove both event notifications and quicksilence
 * notifications//  w  w  w  . j a va2 s  .  c  o  m
 */
public void cancelAllNotifications() {
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(NOTIFICATION_ID);
    nm.cancel(PUBLIC_NOTIFICATION_ID);
}

From source file:de.linuxwhatelse.android.notify.activities.MainActivity.java

private void createTestNotification() {
    this.initChannels(this, getString(R.string.notification_channel_test));

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(Notify.NOTIFICATION_ID_TEST);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, Notify.NOTIFICATION_CHANNEL)
            .setContentTitle(getString(R.string.notification_title))
            .setTicker(getString(R.string.notification_title))
            .setContentText(getString(R.string.notification_text))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.notification_text)))
            .setSmallIcon(R.drawable.ic_textsms).setPriority(NotificationCompat.PRIORITY_DEFAULT);

    notificationManager.notify(Notify.NOTIFICATION_ID_TEST, mBuilder.build());
}

From source file:riddimon.android.asianetautologin.LoginService.java

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

    // cancel the notification so the user knows that the login process
    // is not active
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.cancel(1000);

    logger.info("LoginService is destroyed");
}

From source file:cl.iluminadoschile.pako.floatingdiv.CustomOverlayService.java

@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
    if (Constants.SETTINGS.ACTIVATION_METHOD_KEY.equals(key)) {
        activation_method = prefs.getString(Constants.SETTINGS.ACTIVATION_METHOD_KEY,
                Constants.SETTINGS.ACTIVATION_METHOD_ALONGWITHINGRESS);
        if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            if (activation_method.equals(Constants.SETTINGS.ACTIVATION_METHOD_ALONGWITHINGRESS)) {
                startMonitorIngressRunning();
            } else {
                stoptMonitorIngressRunning();
            }// w  w w.  j a  va 2s  .c  o  m
        }
        Toast.makeText(CustomOverlayService.instance, "Service needs to restart to reflect changes",
                Toast.LENGTH_SHORT).show();
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.cancel(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE);

        Notification notification = foregroundNotification(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE);
        mNotificationManager.notify(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE, notification);
    }
}

From source file:com.daiv.android.twitter.services.SendQueue.java

public void finishedTweetingNotification() {
    try {//from  w w  w.  ja  va 2  s . 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(TAG + "Test_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);

        sendMessage();
    } catch (Exception e) {
        // not attached to activity
    }
}