List of usage examples for android.app NotificationManager cancel
public void cancel(int id)
From source file:org.kde.kdeconnect.Device.java
public void hidePairingNotification() { final NotificationManager notificationManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(notificationId); BackgroundService.removeGuiInUseCounter(context); }
From source file:com.klinker.deskclock.alarms.AlarmNotifications.java
public static void showSnoozeNotification(Context context, AlarmInstance instance) { Log.v("Displaying snoozed notification for alarm instance: " + instance.mId); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Resources resources = context.getResources(); NotificationCompat.Builder notification = new NotificationCompat.Builder(context) .setContentTitle(instance.getLabelOrDefault(context)) .setContentText(resources.getString(R.string.alarm_alert_snooze_until, AlarmUtils.getFormattedTime(context, instance.getAlarmTime()))) .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(true).setAutoCancel(false) .setPriority(NotificationCompat.PRIORITY_MAX); // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance, AlarmInstance.DISMISSED_STATE); notification.addAction(android.R.drawable.ic_menu_close_clear_cancel, resources.getString(R.string.alarm_alert_dismiss_text), PendingIntent.getBroadcast(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content action if instance is owned by alarm long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId); viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX); viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId); viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); nm.cancel(instance.hashCode()); nm.notify(instance.hashCode(), notification.build()); }
From source file:com.yohpapa.research.simplemusicplayer.PlaybackService.java
@Override public void onDestroy() { Log.d(TAG, "onDestroy"); super.onDestroy(); eventBus.unregister(this); finalizePlayer();/*from www.java 2s. c o m*/ NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.cancel(R.id.notification_id); abandonAudioFocus(); }
From source file:com.deepak.myclock.alarms.AlarmNotifications.java
public static void showSnoozeNotification(Context context, AlarmInstance instance) { Log.v("Displaying snoozed notification for alarm instance: " + instance.mId); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Resources resources = context.getResources(); NotificationCompat.Builder notification = new NotificationCompat.Builder(context) .setContentTitle(instance.getLabelOrDefault(context)) .setContentText(resources.getString(R.string.alarm_alert_snooze_until, AlarmUtils.getFormattedTime(context, instance.getAlarmTime()))) .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(true).setAutoCancel(false) .setPriority(NotificationCompat.PRIORITY_MAX); // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance, AlarmInstance.DISMISSED_STATE); notification.addAction(android.R.drawable.ic_menu_close_clear_cancel, resources.getString(R.string.alarm_alert_dismiss_text), PendingIntent.getBroadcast(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content action if instance is owned by alarm long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; Intent viewAlarmIntent = Alarm.createIntent(context, MainActivity.class, alarmId); //viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX); viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId); viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); nm.cancel(instance.hashCode()); nm.notify(instance.hashCode(), notification.build()); }
From source file:net.quduo.pixel.interfaces.android.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // #?//from w ww . ja va2 s .c om // getWindow().requestFeature(Window.FEATURE_PROGRESS); // // ? // this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // // // ??? // // this.requestWindowFeature(Window.FEATURE_NO_TITLE); // // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // setContentView(R.layout.activity_main); // this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.activity_title); setContentView(R.layout.activity_main); // #Application mApp = (MainApplication) getApplication(); // ????? if (DEBUG) Log.d(TAG, "Application ?:" + mApp.getValue()); // ? mApp.setValue("Harvey Ren"); // ????? if (DEBUG) Log.d(TAG, "Application ?:" + mApp.getValue()); // #???, // a.? String able = getResources().getConfiguration().locale.getCountry(); // b.able.equals("CN") // c.? Configuration config = getResources().getConfiguration(); DisplayMetrics dm = getResources().getDisplayMetrics(); config.locale = Locale.SIMPLIFIED_CHINESE; getResources().updateConfiguration(config, dm); // # NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.cancel(0); // #?/? if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { // TODO ?...... } else { // TODO ?...... } // setupActionBar(); /* // #drawer mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); // Set up the drawer. mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); */ initViews(); if (savedInstanceState != null && savedInstanceState.containsKey("main_status")) { mSelectPosition = savedInstanceState.getInt("main_status"); } preferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); /* // ???? SharedPreferences.Editor editor = preferences.edit(); // ? editor.putInt("main_toolbar_selected_index", 0); // ?? editor.commit(); */ mPopupWindowListItem = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object> map1 = new HashMap<String, Object>(); // map1.put("item_image", R.drawable.icon_message); map1.put("item_icon", R.string.icon_chat_add_group); // map1.put("item_text", "" + i + ""); map1.put("item_title", "??"); mPopupWindowListItem.add(map1); HashMap<String, Object> map2 = new HashMap<String, Object>(); // map2.put("item_image", R.drawable.icon_message); map2.put("item_icon", R.string.icon_friend_add); // map2.put("item_text", "" + i + ""); map2.put("item_title", "?"); mPopupWindowListItem.add(map2); HashMap<String, Object> map3 = new HashMap<String, Object>(); // map3.put("item_image", R.drawable.icon_message); map3.put("item_icon", R.string.icon_scan); // map3.put("item_text", "" + i + ""); // map3.put("item_title", "???"); mPopupWindowListItem.add(map3); HashMap<String, Object> map4 = new HashMap<String, Object>(); // map4.put("item_image", R.drawable.icon_message); map4.put("item_icon", R.string.icon_mail); // map4.put("item_text", "" + i + ""); map4.put("item_title", "??"); mPopupWindowListItem.add(map4); }
From source file:com.buddi.client.dfu.DfuActivity.java
private void updateProgressBar(final int progress, final int part, final int total, final boolean error) { switch (progress) { case DfuService.PROGRESS_CONNECTING: mProgressBar.setIndeterminate(true); mTextPercentage.setText(R.string.dfu_status_connecting); break;//from w w w. ja va 2 s . com case DfuService.PROGRESS_STARTING: mProgressBar.setIndeterminate(true); mTextPercentage.setText(R.string.dfu_status_starting); break; case DfuService.PROGRESS_VALIDATING: mProgressBar.setIndeterminate(true); mTextPercentage.setText(R.string.dfu_status_validating); break; case DfuService.PROGRESS_DISCONNECTING: mProgressBar.setIndeterminate(true); mTextPercentage.setText(R.string.dfu_status_disconnecting); break; case DfuService.PROGRESS_COMPLETED: mTextPercentage.setText(R.string.dfu_status_completed); // let's wait a bit until we cancel the notification. When canceled immediately it will be recreated by service again. new Handler().postDelayed(new Runnable() { @Override public void run() { onTransferCompleted(); // if this activity is still open and upload process was completed, cancel the notification final NotificationManager manager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); manager.cancel(DfuService.NOTIFICATION_ID); } }, 200); break; case DfuService.PROGRESS_ABORTED: mTextPercentage.setText(R.string.dfu_status_aborted); // let's wait a bit until we cancel the notification. When canceled immediately it will be recreated by service again. new Handler().postDelayed(new Runnable() { @Override public void run() { onUploadCanceled(); // if this activity is still open and upload process was completed, cancel the notification final NotificationManager manager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); manager.cancel(DfuService.NOTIFICATION_ID); } }, 200); break; default: mProgressBar.setIndeterminate(false); if (error) { showErrorMessage(progress); } else { mProgressBar.setProgress(progress); mTextPercentage.setText(getString(R.string.progress, progress)); if (total > 1) mTextUploading.setText(getString(R.string.dfu_status_uploading_part, part, total)); else mTextUploading.setText(R.string.dfu_status_uploading); } break; } }
From source file:de.yaacc.upnp.server.YaaccUpnpServerService.java
/** * Cancels the notification.//from w w w . j a v a2s . co m */ private void cancleNotification() { NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.cancel(NotificationId.UPNP_SERVER.getId()); }
From source file:com.ota.updates.receivers.AppReceiver.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Bundle extras = intent.getExtras();/*from ww w .j av a2 s . c om*/ long mRomDownloadID = Preferences.getDownloadID(context); if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { long id = extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID); boolean isAddonDownload = false; int keyForAddonDownload = 0; Set<Integer> set = OtaUpdates.getAddonDownloadKeySet(); Iterator<Integer> iterator = set.iterator(); while (iterator.hasNext() && isAddonDownload != true) { int nextValue = iterator.next(); if (id == OtaUpdates.getAddonDownload(nextValue)) { isAddonDownload = true; keyForAddonDownload = nextValue; if (DEBUGGING) { Log.d(TAG, "Checking ID " + nextValue); } } } if (isAddonDownload) { DownloadManager downloadManager = (DownloadManager) context .getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(id); Cursor cursor = downloadManager.query(query); // it shouldn't be empty, but just in case if (!cursor.moveToFirst()) { if (DEBUGGING) Log.e(TAG, "Addon Download Empty row"); return; } int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL != cursor.getInt(statusIndex)) { if (DEBUGGING) Log.w(TAG, "Download Failed"); Log.d(TAG, "Removing Addon download with id " + keyForAddonDownload); OtaUpdates.removeAddonDownload(keyForAddonDownload); AddonActivity.AddonsArrayAdapter.updateProgress(keyForAddonDownload, 0, true); AddonActivity.AddonsArrayAdapter.updateButtons(keyForAddonDownload, false); return; } else { if (DEBUGGING) Log.v(TAG, "Download Succeeded"); Log.d(TAG, "Removing Addon download with id " + keyForAddonDownload); OtaUpdates.removeAddonDownload(keyForAddonDownload); AddonActivity.AddonsArrayAdapter.updateButtons(keyForAddonDownload, true); return; } } else { if (DEBUGGING) Log.v(TAG, "Receiving " + mRomDownloadID); if (id != mRomDownloadID) { if (DEBUGGING) Log.v(TAG, "Ignoring unrelated non-ROM download " + id); return; } DownloadManager downloadManager = (DownloadManager) context .getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(id); Cursor cursor = downloadManager.query(query); // it shouldn't be empty, but just in case if (!cursor.moveToFirst()) { if (DEBUGGING) Log.e(TAG, "Rom download Empty row"); return; } int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL != cursor.getInt(statusIndex)) { if (DEBUGGING) Log.w(TAG, "Download Failed"); Preferences.setDownloadFinished(context, false); if (Utils.isLollipop()) { AvailableActivity.setupMenuToolbar(context); // Reset options menu } else { AvailableActivity.invalidateMenu(); } return; } else { if (DEBUGGING) Log.v(TAG, "Download Succeeded"); Preferences.setDownloadFinished(context, true); AvailableActivity.setupProgress(context); if (Utils.isLollipop()) { AvailableActivity.setupMenuToolbar(context); // Reset options menu } else { AvailableActivity.invalidateMenu(); } return; } } } if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) { long[] ids = extras.getLongArray(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS); for (long id : ids) { if (id != mRomDownloadID) { if (DEBUGGING) Log.v(TAG, "mDownloadID is " + mRomDownloadID + " and ID is " + id); return; } else { Intent i = new Intent(context, AvailableActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } } if (action.equals(MANIFEST_CHECK_BACKGROUND)) { if (DEBUGGING) Log.d(TAG, "Receiving background check confirmation"); boolean updateAvailable = RomUpdate.getUpdateAvailability(context); String filename = RomUpdate.getFilename(context); if (updateAvailable) { Utils.setupNotification(context, filename); Utils.scheduleNotification(context, !Preferences.getBackgroundService(context)); } } if (action.equals(START_UPDATE_CHECK)) { if (DEBUGGING) Log.d(TAG, "Update check started"); new LoadUpdateManifest(context, false).execute(); } if (action.equals(Intent.ACTION_BOOT_COMPLETED)) { if (DEBUGGING) { Log.d(TAG, "Boot received"); } boolean backgroundCheck = Preferences.getBackgroundService(context); if (backgroundCheck) { if (DEBUGGING) Log.d(TAG, "Starting background check alarm"); Utils.scheduleNotification(context, !Preferences.getBackgroundService(context)); } } if (action.equals(IGNORE_RELEASE)) { if (DEBUGGING) { Log.d(TAG, "Ignore release"); } Preferences.setIgnoredRelease(context, Integer.toString(RomUpdate.getVersionNumber(context))); final NotificationManager mNotifyManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setContentTitle(context.getString(R.string.main_release_ignored)) .setSmallIcon(R.drawable.ic_notif) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0)); mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build()); Handler h = new Handler(); long delayInMilliseconds = 1500; h.postDelayed(new Runnable() { public void run() { mNotifyManager.cancel(NOTIFICATION_ID); } }, delayInMilliseconds); } }
From source file:com.chen.mail.utils.NotificationUtils.java
/** * Validate the notifications for the specified account. *///from w w w . ja v a2 s. c o m public static void validateAccountNotifications(Context context, String account) { LogUtils.d(LOG_TAG, "validateAccountNotifications - %s", account); List<NotificationKey> notificationsToCancel = Lists.newArrayList(); // Iterate through the notification map to see if there are any entries that correspond to // labels that are not in the sync set. final NotificationMap notificationMap = getNotificationMap(context); Set<NotificationKey> keys = notificationMap.keySet(); final AccountPreferences accountPreferences = new AccountPreferences(context, account); final boolean enabled = accountPreferences.areNotificationsEnabled(); if (!enabled) { // Cancel all notifications for this account for (NotificationKey notification : keys) { if (notification.account.getAccountManagerAccount().name.equals(account)) { notificationsToCancel.add(notification); } } } else { // Iterate through the notification map to see if there are any entries that // correspond to labels that are not in the notification set. for (NotificationKey notification : keys) { if (notification.account.getAccountManagerAccount().name.equals(account)) { // If notification is not enabled for this label, remember this NotificationKey // to later cancel the notification, and remove the entry from the map final Folder folder = notification.folder; final boolean isInbox = folder.folderUri.equals(notification.account.settings.defaultInbox); final FolderPreferences folderPreferences = new FolderPreferences(context, notification.account.getEmailAddress(), folder, isInbox); if (!folderPreferences.areNotificationsEnabled()) { notificationsToCancel.add(notification); } } } } // Cancel & remove the invalid notifications. if (notificationsToCancel.size() > 0) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); for (NotificationKey notification : notificationsToCancel) { final Folder folder = notification.folder; final int notificationId = getNotificationId(notification.account.getAccountManagerAccount(), folder); LogUtils.d(LOG_TAG, "validateAccountNotifications - cancelling %s / %s", notification.account.name, folder.persistentId); nm.cancel(notificationId); notificationMap.remove(notification); NotificationActionUtils.sUndoNotifications.remove(notificationId); NotificationActionUtils.sNotificationTimestamps.delete(notificationId); } notificationMap.saveNotificationMap(context); } }
From source file:com.embeddedlog.LightUpDroid.alarms.AlarmNotifications.java
public static void showSnoozeNotification(Context context, AlarmInstance instance) { Log.v("Displaying snoozed notification for alarm instance: " + instance.mId); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Resources resources = context.getResources(); NotificationCompat.Builder notification = new NotificationCompat.Builder(context) .setContentTitle(instance.getLabelOrDefault(context)) .setContentText(resources.getString(R.string.alarm_alert_snooze_until, AlarmUtils.getFormattedTime(context, instance.getAlarmTime()))) .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(true).setAutoCancel(false) .setPriority(NotificationCompat.PRIORITY_MAX).setCategory(NotificationCompat.CATEGORY_ALARM); // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance, AlarmInstance.DISMISSED_STATE); notification.addAction(android.R.drawable.ic_menu_close_clear_cancel, resources.getString(R.string.alarm_alert_dismiss_text), PendingIntent.getBroadcast(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content action if instance is owned by alarm long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId); viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX); viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId); viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); nm.cancel(instance.hashCode()); nm.notify(instance.hashCode(), notification.build()); }