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.chen.mail.utils.NotificationUtils.java

/**
 * Clears the notifications for the specified account/folder.
 *///from ww w .  j a  v a  2 s.c om
public static void clearFolderNotification(Context context, Account account, Folder folder,
        final boolean markSeen) {
    LogUtils.v(LOG_TAG, "Clearing all notifications for %s/%s", account.name, folder.name);
    final NotificationMap notificationMap = getNotificationMap(context);
    final NotificationKey key = new NotificationKey(account, folder);
    notificationMap.remove(key);
    notificationMap.saveNotificationMap(context);

    final NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(getNotificationId(account.getAccountManagerAccount(), folder));

    if (markSeen) {
        markSeen(context, folder);
    }
}

From source file:eu.istvank.apps.lenslog.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    getSupportFragmentManager().addOnBackStackChangedListener(this);

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    if (getIntent().hasExtra(NotifySchedulingService.NOTIFICATION_WORN)) {
        //TODO: save date in intent so that we can retrieve whether it still applies for the current date
        DateTime utcDateTime = DateTime.today(TimeZone.getTimeZone("UTC"));
        long utcDateLong = utcDateTime.getMilliseconds(TimeZone.getTimeZone("UTC"));
        boolean isWorn = getIntent().getExtras().getBoolean(NotifySchedulingService.NOTIFICATION_WORN);

        onUpdateWorn(utcDateLong, isWorn);

        // cancel notification
        NotificationManager notificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(NotifySchedulingService.NOTIFICATION_ID);
    }/*from w w w.  j a  v  a 2s .co m*/

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);

    // Read in the flag indicating whether or not the user has demonstrated awareness of the
    // drawer. See PREF_USER_LEARNED_DRAWER for details.
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);

    // check if the user has already accepted the privacy policy
    boolean privacyPolicyAccepted = sp.getBoolean(PREF_USER_ACCEPTED_PRIVACY_POLICY, false);
    if (!privacyPolicyAccepted) {
        HelpUtils.showPrivacyPolicy(this, true);
    }

    mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setStatusBarBackgroundColor(getTitleColor());
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open,
            R.string.navigation_drawer_close) {
        @Override
        public void onDrawerClosed(View drawerView) {
            invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);

            if (!mUserLearnedDrawer) {
                // The user manually opened the drawer; store this flag to prevent auto-showing
                // the navigation drawer automatically in the future.
                mUserLearnedDrawer = true;
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
            }

            invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager()
            .findFragmentById(R.id.navigation_drawer);
    mNavigationDrawerFragment.setUp(this, R.id.navigation_drawer, mDrawerLayout);

    // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer,
    // per the navigation drawer design guidelines.
    if (!mUserLearnedDrawer) {
        mDrawerLayout.openDrawer(findViewById(R.id.navigation_drawer));
    }

    if (savedInstanceState != null) {
        // probably configuration change
        mBackEnabled = savedInstanceState.getBoolean(STATE_BACK_ENABLED);
        setBackEnabled(mBackEnabled);
    } else {
        // app freshly started, show calendar fragment
        onNavigationDrawerItemSelected(NavigationDrawerFragment.SECTION_CALENDAR);
    }

    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });

    mTitle = getTitle();
}

From source file:de.gebatzens.ggvertretungsplan.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(GGApp.GG_APP.provider.getTheme());
    super.onCreate(savedInstanceState);
    GGApp.GG_APP.activity = this;
    savedState = savedInstanceState;/*  ww  w .jav a  2 s  .  c  om*/

    Intent intent = getIntent();
    if (intent != null && intent.getStringExtra("fragment") != null) {
        GGApp.FragmentType type = GGApp.FragmentType.valueOf(intent.getStringExtra("fragment"));
        GGApp.GG_APP.setFragmentType(type);
    }

    mStrings = new String[] { getResources().getString(R.string.substitutionplan),
            getResources().getString(R.string.news), getResources().getString(R.string.cafeteria),
            getResources().getString(R.string.exams) };

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(123);

    setContentView(getLayoutInflater().inflate(R.layout.activity_main, null));

    removeAllFragments();

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    mContent = createFragment();
    transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment");
    transaction.commit();

    if (GGApp.GG_APP.getDataForFragment(GGApp.GG_APP.getFragmentType()) == null)
        GGApp.GG_APP.refreshAsync(null, true, GGApp.GG_APP.getFragmentType());

    mToolbar = (Toolbar) findViewById(R.id.toolbar);

    mToolbar.setBackgroundColor(GGApp.GG_APP.provider.getColor());
    mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {

            if (menuItem.getItemId() == R.id.action_refresh) {
                ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh)).setRefreshing(true);
                GGApp.GG_APP.refreshAsync(new Runnable() {
                    @Override
                    public void run() {
                        ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh))
                                .setRefreshing(false);
                    }
                }, true, GGApp.GG_APP.getFragmentType());
            } else if (menuItem.getItemId() == R.id.action_settings) {
                Intent i = new Intent(MainActivity.this, SettingsActivity.class);
                startActivityForResult(i, 1);
            }

            return false;
        }
    });

    mToolbar.setTitle(GGApp.GG_APP.provider.getFullName());
    mToolbar.setSubtitle(
            mStrings[Arrays.asList(GGApp.FragmentType.values()).indexOf(GGApp.GG_APP.getFragmentType())]);
    mToolbar.inflateMenu(R.menu.toolbar_menu);
    mToolbar.setTitleTextColor(Color.WHITE);
    mToolbar.setSubtitleTextColor(Color.WHITE);

    ((TextView) findViewById(R.id.drawer_image_text)).setText(GGApp.GG_APP.provider.getFullName());

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        GGApp.GG_APP.setStatusBarColorTransparent(getWindow());
        mDrawerLayout.setStatusBarBackgroundColor(GGApp.GG_APP.provider.getDarkColor());
    }

    mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open,
            R.string.drawer_close) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };

    mNacvigationImage = (ImageView) findViewById(R.id.navigation_schoolpicture);
    mNacvigationImage.setImageResource(GGApp.GG_APP.provider.getImage());
    mNavigationSchoolpictureLink = (View) findViewById(R.id.navigation_schoolpicture_link);
    mNavigationSchoolpictureLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View viewIn) {
            mDrawerLayout.closeDrawers();
            Intent linkIntent = new Intent(Intent.ACTION_VIEW);
            linkIntent.setData(Uri.parse(GGApp.GG_APP.provider.getWebsite()));
            startActivity(linkIntent);
        }
    });

    mDrawerLayout.setDrawerListener(mToggle);

    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    //ArrayAdapter<String> aa = new ArrayAdapter<String>(this, R.layout.drawer_list_item, mStrings);
    NavigationListAdapter aa = new NavigationListAdapter(this, mStrings, mIcons);
    mDrawerList.setAdapter(aa);
    mDrawerList.setItemChecked(
            Arrays.asList(GGApp.FragmentType.values()).indexOf(GGApp.GG_APP.getFragmentType()), true);

    mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (GGApp.GG_APP.getFragmentType() != GGApp.FragmentType.values()[position]) {
                GGApp.GG_APP.setFragmentType(GGApp.FragmentType.values()[position]);
                mDrawerLayout.closeDrawers();
                mToolbar.setSubtitle(mStrings[position]);
                mContent = createFragment();
                Animation fadeOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out);
                fadeOut.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                        // Called when the Animation starts
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment);
                        contentFrame.setVisibility(View.INVISIBLE);
                        if (GGApp.GG_APP.getDataForFragment(GGApp.GG_APP.getFragmentType()) == null)
                            GGApp.GG_APP.refreshAsync(null, true, GGApp.GG_APP.getFragmentType());

                        removeAllFragments();

                        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                        transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment");
                        transaction.commit();
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                        // This is called each time the Animation repeats
                    }
                });
                FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment);
                contentFrame.startAnimation(fadeOut);
            } else {
                mDrawerLayout.closeDrawers();
            }
        }
    });
    ListviewHelper.getListViewSize(mDrawerList);

    /*mDrawerFirstUse = (TextView) findViewById(R.id.left_drawer_firstuse);
    mDrawerFirstUse.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View viewIn) {
        mDrawerLayout.closeDrawers();
        Intent i = new Intent(MainActivity.this, FirstUseActivity.class);
        startActivityForResult(i, 1);
    }
    });*/

    mDrawerSettings = (TextView) findViewById(R.id.left_drawer_settings);
    mDrawerSettings.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View viewIn) {
            mDrawerLayout.closeDrawers();
            Intent i = new Intent(MainActivity.this, SettingsActivity.class);
            startActivityForResult(i, 1);
        }
    });

    //wait for vps
    new AsyncTask<Object, Void, Void>() {

        @Override
        protected Void doInBackground(Object... params) {
            boolean b = true;
            while (b) {
                switch (GGApp.GG_APP.getFragmentType()) {
                case PLAN:
                    b = GGApp.GG_APP.plans == null;
                    break;
                case NEWS:
                    b = GGApp.GG_APP.news == null;
                    break;
                case MENSA:
                    b = GGApp.GG_APP.mensa == null;
                    break;
                case EXAMS:
                    b = GGApp.GG_APP.exams == null;
                    break;
                }
            }

            return null;
        }
    }.execute();

}

From source file:net.xisberto.phonetodesktop.GoogleTasksActivity.java

private void dismissNotification(int notificationId) {
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.cancel(notificationId);
}

From source file:com.rareventure.gps2.GpsTrailerService.java

@Override
public void onDestroy() {
    Log.d(TAG, "GPS Service Shutdown");

    GTG.removeGTGEventListener(gtgEventListener);

    if (currentNotificationSetting != null && !currentNotificationSetting.sticky) {
        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        nm.cancel(GTG.FROG_NOTIFICATION_ID);
    }//from   w w  w . j a va 2  s .c  om

    if (gpsManager != null)
        gpsManager.shutdown();

    if (batteryReceiver != null)
        unregisterReceiver(batteryReceiver);
}

From source file:com.digi.android.wva.WvaApplication.java

/**
 * Dismiss the alarm notification from the status bar, if it's there.
 * Essentially the opposite of calling//from w  w  w  .ja  va  2 s .  co m
 * {@link #showAlarmNotification(String, VehicleData)}
 */
public void dismissAlarmNotification() {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(ALARM_NOTIF_ID);
}

From source file:de.yaacc.player.LocalImagePlayer.java

/**
 * Cancels the notification./*w w  w. j a  v  a 2 s.  co  m*/
 */
private void cancleNotification() {
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.cancel(getNotificationId());

}

From source file:com.tvs.signaltracker.STService.java

@Override
public void onDestroy() {
    ServiceHandler.removeCallbacks(ReCheck);
    ServiceHandler.removeCallbacks(ReSendRun);
    ServiceHandler.removeCallbacks(LightMode);

    if (CommonHandler.ServiceMode == 2 || CommonHandler.ServiceMode == 4) {
        Log.i("SignalTracker::STService", "Parando trabalhos");
        try {/*from  ww  w  . ja v a 2  s  .  c  om*/
            if (mlocManager != null) {
                mlocManager.removeGpsStatusListener(GPSs);
                mlocManager.removeUpdates(GPSLocListener);
                mlocManager.removeUpdates(NetLocListener);
            }
            if (Tel != null)
                Tel.listen(MyListener, PhoneStateListener.LISTEN_NONE);
        } catch (Exception e) {
        }
        ;

        MyListener = null;
        Tel = null;
        mlocManager = null;
        GPSs = null;
        GPSLocListener = null;
        NetLocListener = null;
        CommonHandler.GPSFix = false;
        CommonHandler.NumSattelites = 0;
        CommonHandler.NumConSattelites = 0;
        try {
            String ns = Context.NOTIFICATION_SERVICE;
            NotificationManager nMgr = (NotificationManager) this.getSystemService(ns);
            nMgr.cancel(NOTIFICATION);
        } catch (Exception e) {
        }
    }
    Toast.makeText(getApplicationContext(), getResources().getString(R.string.stservicestopped),
            Toast.LENGTH_LONG).show();
    if (!CommonHandler.KillService) {
        Intent myIntent = new Intent(STService.this, STService.class);
        PendingIntent pendingIntent = PendingIntent.getService(STService.this, 0, myIntent, 0);
        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.add(Calendar.SECOND, 2);
        alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
    }
    CommonHandler.KillService = false;
    LocalRunning = false;
    Opened = false;
}

From source file:net.bither.activity.hot.HotActivity.java

private void deleteNotification() {
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(BitherSetting.NOTIFICATION_ID_COINS_RECEIVED);
}

From source file:org.ulteo.ovd.AndRdpActivity.java

@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void onDestroy() {
    smHandler.unlistenSm();/*w  w w.j  a  v a2 s .  c  o m*/
    smHandler.stopStatusPoll();
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancel(1);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.removePrimaryClipChangedListener(clipChangedListener);
    }

    super.onDestroy();
}