List of usage examples for android.support.v4.app NotificationManagerCompat cancel
public void cancel(String str, int i)
From source file:com.android.messaging.sms.SmsStorageStatusManager.java
/** * Cancel the notification/*from w ww . j ava 2 s .co m*/ */ public static void cancelStorageLowNotification() { final NotificationManagerCompat notificationManager = NotificationManagerCompat .from(Factory.get().getApplicationContext()); notificationManager.cancel(getNotificationTag(), PendingIntentConstants.SMS_STORAGE_LOW_NOTIFICATION_ID); }
From source file:com.android.messaging.receiver.SmsReceiver.java
/** * Cancel the notification/*from w w w. j a v a2 s.co m*/ */ public static void cancelSecondaryUserNotification() { final NotificationManagerCompat notificationManager = NotificationManagerCompat .from(Factory.get().getApplicationContext()); notificationManager.cancel(getNotificationTag(), PendingIntentConstants.SMS_SECONDARY_USER_NOTIFICATION_ID); }
From source file:com.android.messaging.datamodel.BugleNotifications.java
/** * Cancel all notifications of a certain type. * * @param type Message or error notifications from Constants. * @param conversationId If set, cancel the notification for this * conversation only. For message notifications, this only works * if the notifications are bundled (group children). * @param isBundledNotification True if this notification is part of a * notification bundle. This only applies to message notifications, * which are bundled together with other message notifications. *///from w w w. j a v a2 s . c om private static synchronized void cancel(final int type, final String conversationId, final boolean isBundledNotification) { final String notificationTag = buildNotificationTag(type, conversationId, isBundledNotification); final NotificationManagerCompat notificationManager = NotificationManagerCompat .from(Factory.get().getApplicationContext()); // Find all pending notifications and cancel them. synchronized (sPendingNotifications) { final Iterator<NotificationState> iter = sPendingNotifications.iterator(); while (iter.hasNext()) { final NotificationState notifState = iter.next(); if (notifState.mType == type) { notifState.mCanceled = true; if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) { LogUtil.v(TAG, "Canceling pending notification"); } iter.remove(); } } } notificationManager.cancel(notificationTag, type); if (LogUtil.isLoggable(TAG, LogUtil.DEBUG)) { LogUtil.d(TAG, "Canceled notifications of type " + type); } // Message notifications for multiple conversations can be grouped together (see comment in // createMessageNotification). We need to do bookkeeping to track the current set of // notification group children, including removing them when we cancel notifications). if (type == PendingIntentConstants.SMS_NOTIFICATION_ID) { final Context context = Factory.get().getApplicationContext(); final ConversationIdSet groupChildIds = getGroupChildIds(context); if (groupChildIds != null && groupChildIds.size() > 0) { // If a conversation is specified, remove just that notification. Otherwise, // we're removing the group summary so clear all children. if (conversationId != null) { groupChildIds.remove(conversationId); writeGroupChildIds(context, groupChildIds); } else { cancelStaleGroupChildren(groupChildIds, null); // We'll update the group children preference as we cancel each child, // so we don't need to do it here. } } } }
From source file:com.android.messaging.datamodel.MessageNotificationState.java
/** * Check for failed messages and post notifications as needed. * TODO: Rewrite this as a NotificationState. *///from ww w . j av a2s . c o m public static void checkFailedMessages() { final DatabaseWrapper db = DataModel.get().getDatabase(); final Cursor messageDataCursor = db.query(DatabaseHelper.MESSAGES_TABLE, MessageData.getProjection(), FailedMessageQuery.FAILED_MESSAGES_WHERE_CLAUSE, null /*selectionArgs*/, null /*groupBy*/, null /*having*/, FailedMessageQuery.FAILED_ORDER_BY); try { final Context context = Factory.get().getApplicationContext(); final Resources resources = context.getResources(); final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); if (messageDataCursor != null) { final MessageData messageData = new MessageData(); final HashSet<String> conversationsWithFailedMessages = new HashSet<String>(); // track row ids in case we want to display something that requires this // information final ArrayList<Integer> failedMessages = new ArrayList<Integer>(); int cursorPosition = -1; final long when = 0; messageDataCursor.moveToPosition(-1); while (messageDataCursor.moveToNext()) { messageData.bind(messageDataCursor); final String conversationId = messageData.getConversationId(); if (DataModel.get().isNewMessageObservable(conversationId)) { // Don't post a system notification for an observable conversation // because we already show an angry red annotation in the conversation // itself or in the conversation preview snippet. continue; } cursorPosition = messageDataCursor.getPosition(); failedMessages.add(cursorPosition); conversationsWithFailedMessages.add(conversationId); } if (LogUtil.isLoggable(TAG, LogUtil.DEBUG)) { LogUtil.d(TAG, "Found " + failedMessages.size() + " failed messages"); } if (failedMessages.size() > 0) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); CharSequence line1; CharSequence line2; final boolean isRichContent = false; ConversationIdSet conversationIds = null; PendingIntent destinationIntent; if (failedMessages.size() == 1) { messageDataCursor.moveToPosition(cursorPosition); messageData.bind(messageDataCursor); final String conversationId = messageData.getConversationId(); // We have a single conversation, go directly to that conversation. destinationIntent = UIIntents.get().getPendingIntentForConversationActivity(context, conversationId, null /*draft*/); conversationIds = ConversationIdSet.createSet(conversationId); final String failedMessgeSnippet = messageData.getMessageText(); int failureStringId; if (messageData.getStatus() == MessageData.BUGLE_STATUS_INCOMING_DOWNLOAD_FAILED) { failureStringId = R.string.notification_download_failures_line1_singular; } else { failureStringId = R.string.notification_send_failures_line1_singular; } line1 = resources.getString(failureStringId); line2 = failedMessgeSnippet; // Set rich text for non-SMS messages or MMS push notification messages // which we generate locally with rich text // TODO- fix this // if (messageData.isMmsInd()) { // isRichContent = true; // } } else { // We have notifications for multiple conversation, go to the conversation // list. destinationIntent = UIIntents.get().getPendingIntentForConversationListActivity(context); int line1StringId; int line2PluralsId; if (messageData.getStatus() == MessageData.BUGLE_STATUS_INCOMING_DOWNLOAD_FAILED) { line1StringId = R.string.notification_download_failures_line1_plural; line2PluralsId = R.plurals.notification_download_failures; } else { line1StringId = R.string.notification_send_failures_line1_plural; line2PluralsId = R.plurals.notification_send_failures; } line1 = resources.getString(line1StringId); line2 = resources.getQuantityString(line2PluralsId, conversationsWithFailedMessages.size(), failedMessages.size(), conversationsWithFailedMessages.size()); } line1 = applyWarningTextColor(context, line1); line2 = applyWarningTextColor(context, line2); final PendingIntent pendingIntentForDelete = UIIntents.get() .getPendingIntentForClearingNotifications(context, BugleNotifications.UPDATE_ERRORS, conversationIds, 0); builder.setContentTitle(line1).setTicker(line1) .setWhen(when > 0 ? when : System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_failed_light).setDeleteIntent(pendingIntentForDelete) .setContentIntent(destinationIntent) .setSound(UriUtil.getUriForResourceId(context, R.raw.message_failure)); if (isRichContent && !TextUtils.isEmpty(line2)) { final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(builder); if (line2 != null) { inboxStyle.addLine(Html.fromHtml(line2.toString())); } builder.setStyle(inboxStyle); } else { builder.setContentText(line2); } if (builder != null) { notificationManager.notify(BugleNotifications .buildNotificationTag(PendingIntentConstants.MSG_SEND_ERROR, null), PendingIntentConstants.MSG_SEND_ERROR, builder.build()); } } else { notificationManager.cancel( BugleNotifications.buildNotificationTag(PendingIntentConstants.MSG_SEND_ERROR, null), PendingIntentConstants.MSG_SEND_ERROR); } } } finally { if (messageDataCursor != null) { messageDataCursor.close(); } } }