NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); StatusBarNotification[] activeNotifications = notificationManager.getActiveNotifications(); if (activeNotifications.length != 0) { for (StatusBarNotification activeNotification : activeNotifications) { //根据渠道id取消同一渠道id下的所有通知 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (activeNotification.getNotification().getChannelId().equals("1")) { notificationManager.cancel(activeNotification.getId()); } } //根据通知内容 取消通知 CharSequence tickerText = activeNotification.getNotification().tickerText; if (null != tickerText) { if ("来电话了".equals(tickerText.toString())) { notificationManager.cancel(activeNotification.getId()); } } } }
Android 取消推送通知Notification
最新推荐文章于 2024-07-15 10:34:46 发布