List of usage examples for android.app NotificationManager cancel
public void cancel(int id)
From source file:com.jtechme.apphub.FDroid.java
public void removeNotification(int id) { NotificationManager nMgr = (NotificationManager) getBaseContext() .getSystemService(Context.NOTIFICATION_SERVICE); nMgr.cancel(id); }
From source file:net.micode.soundrecorder.RecorderService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Bundle bundle = intent.getExtras();//www . ja v a 2s . c om if (bundle != null && bundle.containsKey(ACTION_NAME)) { switch (bundle.getInt(ACTION_NAME, ACTION_INVALID)) { case ACTION_START_RECORDING: localStartRecording(bundle.getInt(ACTION_PARAM_FORMAT), bundle.getString(ACTION_PARAM_PATH), bundle.getBoolean(ACTION_PARAM_HIGH_QUALITY), bundle.getLong(ACTION_PARAM_MAX_FILE_SIZE)); break; case ACTION_STOP_RECORDING: localStopRecording(); break; case ACTION_ENABLE_MONITOR_REMAIN_TIME: if (mRecorder != null) { mNeedUpdateRemainingTime = true; mHandler.post(mUpdateRemainingTime); } break; case ACTION_DISABLE_MONITOR_REMAIN_TIME: mNeedUpdateRemainingTime = false; if (mRecorder != null) { showRecordingNotification(); NotificationManager nMgr = (NotificationManager) getApplicationContext() .getSystemService(NOTIFICATION_SERVICE); nMgr.cancel(notifyID); } break; default: break; } return START_STICKY; } return super.onStartCommand(intent, flags, startId); }
From source file:org.mozilla.gecko.fxa.sync.FxAccountNotificationManager.java
/** * Reflect new Firefox Account state to the notification manager: show or hide * notifications reflecting the state of a Firefox Account. * * @param context/* w w w.j av a 2 s. com*/ * Android context. * @param fxAccount * Firefox Account to reflect to the notification manager. */ public void update(Context context, AndroidFxAccount fxAccount) { final NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); final State state = fxAccount.getState(); final Action action = state.getNeededAction(); if (action == Action.None) { Logger.info(LOG_TAG, "State " + state.getStateLabel() + " needs no action; cancelling any existing notification."); notificationManager.cancel(notificationId); return; } if (!localeUpdated) { localeUpdated = true; BrowserLocaleManager.getInstance().getAndApplyPersistedLocale(context); } final String title; final String text; final Intent notificationIntent; if (action == Action.NeedsFinishMigrating) { TelemetryWrapper.addToHistogram(TelemetryContract.SYNC11_MIGRATION_NOTIFICATIONS_OFFERED, 1); title = context.getResources().getString(R.string.fxaccount_sync_finish_migrating_notification_title); text = context.getResources().getString(R.string.fxaccount_sync_finish_migrating_notification_text, state.email); notificationIntent = new Intent(context, FxAccountFinishMigratingActivity.class); } else { title = context.getResources().getString(R.string.fxaccount_sync_sign_in_error_notification_title); text = context.getResources().getString(R.string.fxaccount_sync_sign_in_error_notification_text, state.email); notificationIntent = new Intent(context, FxAccountStatusActivity.class); } Logger.info(LOG_TAG, "State " + state.getStateLabel() + " needs action; offering notification with title: " + title); FxAccountUtils.pii(LOG_TAG, "And text: " + text); final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); final Builder builder = new NotificationCompat.Builder(context); builder.setContentTitle(title).setContentText(text).setSmallIcon(R.drawable.ic_status_logo) .setAutoCancel(true).setContentIntent(pendingIntent); notificationManager.notify(notificationId, builder.build()); }
From source file:com.embeddedlog.LightUpDroid.timer.TimerReceiver.java
private void cancelInUseNotification(final Context context) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(IN_USE_NOTIFICATION_ID); }
From source file:com.embeddedlog.LightUpDroid.timer.TimerReceiver.java
private void cancelTimesUpNotification(final Context context, TimerObj timerObj) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(timerObj.mTimerId); if (Timers.LOGGING) { Log.v(TAG, "Canceling times-up notification for " + timerObj.getLabelOrDefault(context) + " #" + timerObj.mTimerId);/* www . j av a 2 s.c om*/ } }
From source file:at.ac.uniklu.mobile.sportal.service.MutingService.java
private void removeNotification(int id) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(id); }
From source file:de.unipassau.isl.evs.ssh.app.handler.AppNotificationHandler.java
/** * Builds the Notification with the given text and displays it on the user-device. * If user clicks on it, the ssh app will open. * * @param title for the Notification * @param text under the title to give further information * @param openThisFragment Which fragment should be opened when clicked on the notification * Add string to MainActivity (onCreate) if not already declared. * @param notificationID unique ID for this type of Notification *///w w w .j ava 2 s . com private void displayNotification(String title, String text, Class openThisFragment, int notificationID) { //If Notification is clicked send to this Page Context context = requireComponent(ContainerService.KEY_CONTEXT); Intent resultIntent = new Intent(context, AppMainActivity.class); resultIntent.putExtra(AppMainActivity.KEY_NOTIFICATION_FRAGMENT, openThisFragment); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(AppMainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context); notificationBuilder.setContentIntent(resultPendingIntent).setDefaults(Notification.DEFAULT_ALL) .setSmallIcon(R.drawable.ic_home_light).setWhen(System.currentTimeMillis()).setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle().bigText(text)) .setLights(R.color.colorPrimary, 3000, 3000); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //Delete old BellRang if door gets unlocked if (notificationID == DOOR_UNLATCHED.ordinal()) { notificationManager.cancel(BELL_RANG.ordinal()); } //Delete old HolidayMode switched on notification if HolidayMode is switched off if (notificationID == HOLIDAY_MODE_SWITCHED_OFF.ordinal()) { notificationManager.cancel(HOLIDAY_MODE_SWITCHED_ON.ordinal()); } //^vis versa HolidayMode if (notificationID == HOLIDAY_MODE_SWITCHED_ON.ordinal()) { notificationManager.cancel(HOLIDAY_MODE_SWITCHED_OFF.ordinal()); } //Delete old door locked notification if door is unlocked if (notificationID == DOOR_UNLOCKED.ordinal()) { notificationManager.cancel(DOOR_LOCKED.ordinal()); } //^vis versa door notification if (notificationID == DOOR_LOCKED.ordinal()) { notificationManager.cancel(DOOR_UNLOCKED.ordinal()); } //Send notification out to Device if (notificationManager != null) { notificationManager.notify(notificationID, notificationBuilder.build()); } else { Log.e(TAG, "ERROR! context.getSystemService(Context.NOTIFICATION_SERVICE) was null (AppNotificationHandler)"); } }
From source file:com.melchor629.musicote.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { // Set the user interface layout for this Activity // The layout file is defined in the project res/layout/main.xml file super.onCreate(savedInstanceState); setContentView(R.layout.main);/* w w w . j ava2 s.c o m*/ appContext = getApplicationContext(); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.mainLayout); swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimaryDark, R.color.colorGrey600); final ListView list = (ListView) findViewById(android.R.id.list); list.setOnScrollListener(new ListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { boolean enable = false; if (list != null && list.getChildCount() > 0) { // check if the first item of the list is visible boolean firstItemVisible = list.getFirstVisiblePosition() == 0; // check if the top of the first item is visible boolean topOfFirstItemVisible = list.getChildAt(0).getTop() == 0; // enabling or disabling the refresh layout enable = firstItemVisible && topOfFirstItemVisible; } swipeRefreshLayout.setEnabled(enable); } }); getActionBar().setIcon(R.drawable.ic_launcher); getActionBar().setDisplayUseLogoEnabled(true); // La app prueba en busca de la direccin correcta WifiManager mw = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wi = mw.getConnectionInfo(); String SSID = wi.getSSID(); Log.i("MainActivity", "Wifi conectado: " + SSID + " " + (SSID != null ? SSID.equals("Madrigal") : "")); if (SSID == null) { SSID = ""; Toast.makeText(this, getString(R.string.no_wifi), Toast.LENGTH_LONG).show(); } if (SSID.equals("Madrigal") || SSID.contains("Madrigal") || System.getProperty("os.version").equals("3.4.67+")) { MainActivity.HOST = "192.168.1.133"; } else { MainActivity.HOST = "reinoslokos.no-ip.org"; } Log.i("MainActivity", "HOST: " + HOST); //Deletes the notification if remains (BUG) NotificationManager mn = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (Reproductor.a == -1) mn.cancel(1); mn.cancel(3); //Revisa la base de datos DB mDbHelper = new DB(getBaseContext()); SQLiteDatabase db = mDbHelper.getWritableDatabase(); //Actualizacin de la lista if (mDbHelper.isNecesaryUpgrade(db) && Utils.HostTest(HOST) == 200) async(); else cursordb(db); db.close(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }
From source file:fr.paug.droidcon.service.SessionAlarmService.java
private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(NOTIFICATION_ID); final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > sessionStart) { LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart); return;// w w w . j av a2s . com } // By default, sets alarm to go off at 10 minutes before session start time. If alarm // offset is provided, alarm is set to go off by that much time from now. long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionStart - MILLI_TEN_MINUTES; } else { alarmTime = currentTime + alarmOffset; } LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString()); final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class); // Setting data to ensure intent's uniqueness for different session start times. notifIntent.setData( new Uri.Builder().authority("fr.paug.droidcon").path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); LOGD(TAG, "-> Intent extra: session start " + sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); LOGD(TAG, "-> Intent extra: session end " + sessionEnd); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset); LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset); PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Schedule an alarm to be fired to notify user of added sessions are about to begin. LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime); am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:com.money.manager.ex.sync.SyncService.java
private void afterDownload(NotificationManager notificationManager, File tempFile, File localFile, CloudMetaData remoteFile, SyncManager sync) { if (notificationManager == null) return;//from ww w . ja v a 2s . c om notificationManager.cancel(SyncConstants.NOTIFICATION_SYNC_IN_PROGRESS); // copy file try { MmxFileUtils.copy(tempFile, localFile); tempFile.delete(); } catch (IOException e) { Timber.e(e, "copying downloaded database file"); return; } sync.saveRemoteLastModifiedDate(localFile.getAbsolutePath(), remoteFile); // Create the notification for opening of the downloaded file. // The Intent is passed to the notification and called if clicked on. Intent intent = new SyncCommon().getIntentForOpenDatabase(getApplicationContext(), localFile); PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), RequestCodes.SELECT_FILE, intent, 0); Notification completeNotification = new SyncNotificationFactory(getApplicationContext()) .getNotificationDownloadComplete(pendingIntent); // notify notificationManager.notify(SyncConstants.NOTIFICATION_SYNC_OPEN_FILE, completeNotification); }