List of usage examples for android.app NotificationManager cancel
public void cancel(int id)
From source file:com.veniosg.dir.android.util.Notifier.java
public static void showCompressDoneNotification(boolean success, int notId, File zipFile, Context context) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (!shouldShowDoneNotification(notId, success)) { notificationManager.cancel(notId); } else {//from w w w .ja v a 2 s. co m Intent browseIntent = new Intent(context, FileManagerActivity.class); browseIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); browseIntent.setData(Uri.fromFile(zipFile.getParentFile())); Notification not = new NotificationCompat.Builder(context, CHANNEL_FILEOPS).setAutoCancel(true) .setContentTitle(context.getString( success ? R.string.notif_compressed_success : R.string.notif_compressed_fail)) .setContentText(zipFile.getName()) .setContentIntent(getActivity(context, 0, browseIntent, FLAG_CANCEL_CURRENT)).setOngoing(false) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setSmallIcon(R.drawable.ic_stat_notify_compress_5) .setTicker(context.getString( success ? R.string.notif_compressed_success : R.string.notif_compressed_fail)) .setOnlyAlertOnce(true).build(); notificationManager.notify(notId, not); } }
From source file:com.veniosg.dir.android.util.Notifier.java
public static void showExtractDoneNotification(boolean success, int notId, File extractedTo, Context context) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (!shouldShowDoneNotification(notId, success)) { notificationManager.cancel(notId); } else {// ww w . j a va 2 s. co m Intent browseIntent = new Intent(context, FileManagerActivity.class); browseIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); browseIntent.setData(Uri.fromFile(extractedTo)); Notification not = new NotificationCompat.Builder(context, CHANNEL_FILEOPS).setAutoCancel(true) .setContentTitle(context .getString(success ? R.string.notif_extracted_success : R.string.notif_extracted_fail)) .setContentText(extractedTo.getName()) .setContentIntent(getActivity(context, 0, browseIntent, FLAG_CANCEL_CURRENT)).setOngoing(false) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setSmallIcon(R.drawable.ic_stat_notify_compress_5) .setTicker(context .getString(success ? R.string.notif_extracted_success : R.string.notif_extracted_fail)) .setOnlyAlertOnce(true).build(); notificationManager.notify(notId, not); } }
From source file:com.fede.Utilities.GeneralUtils.java
public static void removeNotifications(Context c) { String svcName = Context.NOTIFICATION_SERVICE; NotificationManager notificationManager = (NotificationManager) c.getSystemService(svcName); notificationManager.cancel(1); }
From source file:com.odoo.core.utils.notification.ONotificationBuilder.java
public static void cancelNotification(Context context, int id) { NotificationManager nMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nMgr.cancel(id); }
From source file:org.mozilla.gecko.tabqueue.TabQueueHelper.java
protected static void removeNotification(Context context) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(TAB_QUEUE_NOTIFICATION_ID); }
From source file:com.nononsenseapps.feeder.model.RssNotifications.java
/** * Notify new items// ww w . j a va 2 s .co m * * @param context */ public static void notify(final Context context) { ArrayList<FeedItemSQL> feedItems = getItemsToNotify(context); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (feedItems.isEmpty()) { // Dismiss since it should be empty nm.cancel(mId); return; } NotificationCompat.Style notStyle; String contentTitle, contentText = ""; // Many items if (feedItems.size() == 1) { notStyle = new NotificationCompat.BigTextStyle(); contentTitle = "1 new RSS-story"; ((NotificationCompat.BigTextStyle) notStyle).setBigContentTitle(contentTitle); contentText = feedItems.get(0).feedtitle + " \u2014 " + feedItems.get(0).plaintitle; ((NotificationCompat.BigTextStyle) notStyle).bigText(contentText); } else { notStyle = new NotificationCompat.InboxStyle(); contentTitle = feedItems.size() + " new RSS-stories"; ((NotificationCompat.InboxStyle) notStyle).setBigContentTitle(contentTitle); for (FeedItemSQL item : feedItems) { ((NotificationCompat.InboxStyle) notStyle).addLine(item.feedtitle + " \u2014 " + item.plaintitle); contentText += item.feedtitle + " \u2014 " + item.plaintitle + "\n"; } } // Actions: markAsRead, enclosureplay, openlink // Priority: Low // Category: CATEGORY_SOCIAL // Style: INBOX Bitmap bm = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher); // TODO icon NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_rss).setLargeIcon(bm).setNumber(feedItems.size()) .setAutoCancel(true).setContentTitle(contentTitle).setContentText(contentText) .setCategory(NotificationCompat.CATEGORY_SOCIAL).setPriority(NotificationCompat.PRIORITY_LOW); if (feedItems.size() == 1) { if (feedItems.get(0).description != null && !feedItems.get(0).description.isEmpty()) { Intent intent = new Intent(context, ReaderActivity.class); ReaderActivity.setRssExtras(intent, feedItems.get(0)); mBuilder.setContentIntent( PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); } else { Intent intent = new Intent(context, FeedActivity.class); // TODO Set feed arguments mBuilder.setContentIntent( PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); } if (feedItems.get(0).enclosurelink != null) { mBuilder.addAction(R.drawable.ic_action_av_play_circle_outline, "Open file", PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, Uri.parse(feedItems.get(0).enclosurelink)), PendingIntent.FLAG_UPDATE_CURRENT)); } mBuilder.addAction(R.drawable.ic_action_location_web_site, "Open in browser", PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, Uri.parse(feedItems.get(0).link)), PendingIntent.FLAG_UPDATE_CURRENT)); } else { Intent intent = new Intent(context, FeedActivity.class); mBuilder.setContentIntent( PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); } // TODO? // mBuilder.addAction(R.drawable.ic_action_done_all, context.getString(R.string.mark_all_as_read), asreadpe); notStyle.setBuilder(mBuilder); // mId allows you to update the notification later on. nm.notify(mId, notStyle.build()); }
From source file:de.azapps.mirakel.reminders.ReminderAlarm.java
public static void closeNotificationFor(final Context context, final Long taskId) { final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(DefinitionsHelper.NOTIF_REMINDER + taskId.intValue()); allReminders.remove(taskId);/*w w w. j a v a 2 s . c om*/ }
From source file:com.velli.passwordmanager.ApplicationBase.java
public static void hideLogOutNotification() { NotificationManager notificationManager = (NotificationManager) getAppContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID); }
From source file:com.paranoid.halo.utils.Notes.java
public static void setNoteByKey(Context context, String key) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Note[] notes = new Note[NOTES.length]; for (int i = 0; i < notes.length; i++) { notes[i] = new Note(NOTES[i], sharedPreferences.getString(NOTES[i], null), NOTE_NOTIF_IDS[i]); }//from w w w . j a v a 2 s . c o m NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); for (Note note : notes) { if (key.equals(note.getId())) { String content = note.getContent(); if (content == null || content.isEmpty()) { notificationManager.cancel(note.getNotificationId()); break; } showNoteNotification(context, notificationManager, note.getNotificationId(), content); } } }
From source file:com.footprint.cordova.plugin.localnotification.LocalNotification.java
/** * Cancel a specific notification that was previously registered. * * @param notificationId/*from w ww .ja va2 s .c om*/ * The original ID of the notification that was used when it was * registered using add() */ public static void cancel(String notificationId) { /* * Create an intent that looks similar, to the one that was registered * using add. Making sure the notification id in the action is the same. * Now we can search for such an intent using the 'getService' method * and cancel it. */ Intent intent = new Intent(context, Receiver.class).setAction("" + notificationId); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); AlarmManager am = getAlarmManager(); NotificationManager nc = getNotificationManager(); am.cancel(pi); try { nc.cancel(Integer.parseInt(notificationId)); } catch (Exception e) { } fireEvent("cancel", notificationId, ""); }