Integer key = 1; @Override public void onNotificationPosted(StatusBarNotification sbn) { Notification n = sbn.getNotification(); if (doINeedToDisableVibration(sbn)) { cancelNotification(sbn.getKey()); n.defaults &= ~Notification.DEFAULT_VIBRATE; n.vibrate = null; NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); synchronized(key) { nm.notify(key++, n); } } }
private String getKey(StatusBarNotification statusBarNotification) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return statusBarNotification.getKey(); else return statusBarNotification.getPackageName() + "/" + String.valueOf(statusBarNotification.getId()); } }
/** * http://stackoverflow.com/questions/9292032/extract-notification-text-from-parcelable-contentview-or-contentintent * */ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public static boolean notificationMatchesFilter(StatusBarNotification sbn, NotificationListenerService.RankingMap rankingMap) { NotificationListenerService.Ranking ranking = new NotificationListenerService.Ranking(); return rankingMap.getRanking(sbn.getKey(), ranking) && ranking.matchesInterruptionFilter(); }
@Override public void onNotificationPosted(StatusBarNotification notification) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(BlockerListener.this); if (preferences.getBoolean(Utils.PREF_ENABLED, false)) { HashSet<String> blocked = new HashSet<>(Arrays.asList(preferences.getString(Utils.PREF_PACKAGES_BLOCKED, "").split(";"))); if (blocked.contains(notification.getPackageName())) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cancelNotification(notification.getKey()); } else { //noinspection deprecation cancelNotification(notification.getPackageName(), notification.getTag(), notification.getId()); } } } }
private static String getNotificationKeyCompat(StatusBarNotification statusBarNotification) { String result; // first check if it's one of our remoteIds String tag = statusBarNotification.getTag(); if (tag != null && tag.startsWith("kdeconnectId:")) result = Integer.toString(statusBarNotification.getId()); else if (Build.VERSION.SDK_INT >= 21) { result = statusBarNotification.getKey(); } else { String packageName = statusBarNotification.getPackageName(); int id = statusBarNotification.getId(); String safePackageName = (packageName == null) ? "" : packageName; String safeTag = (tag == null) ? "" : tag; result = safePackageName + ":" + safeTag + ":" + id; } return result; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void writePropertiesLollipop(JsonWriter writer, StatusBarNotification sbn) throws IOException { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return; } writer.name("key").value(sbn.getKey()); writer.name("groupKey").value(sbn.getGroupKey()); }
return new TvRecommendation( packageName, paramStatusBarNotification.getKey(), l, group,
public static NotificationKeyData fromNotification(StatusBarNotification sbn) { Notification notif = sbn.getNotification(); return new NotificationKeyData(sbn.getKey(), AndroidVersion.isAtLeastOreo() ? notif.getShortcutId() : null, notif.number); }
private void sendNotificationWithStandardUI(byte filterResult, StatusBarNotification statusBarNotification) { DataBundle dataBundle = new DataBundle(); int id = NotificationJobService.NOTIFICATION_POSTED_STANDARD_UI; int jobId = + abs((int) (long) (statusBarNotification.getId() % 10000L)); dataBundle.putParcelable("data", StatusBarNotificationData.from(this, statusBarNotification, false)); NotificationStore.addStandardNotification(statusBarNotification.getKey(), dataBundle); scheduleJob(id, jobId, statusBarNotification.getKey()); /* * Disabled while testing JobScheduler * //Connect transporter Transporter notificationTransporter = TransporterClassic.get(this, "com.huami.action.notification"); notificationTransporter.connectTransportService(); notificationTransporter.send("add", dataBundle, new Transporter.DataSendResultCallback() { @Override public void onResultBack(DataTransportResult dataTransportResult) { log.d(dataTransportResult.toString()); } }); //Disconnect transporter to avoid leaking notificationTransporter.disconnectTransportService(); log.i("NotificationService StandardUI: " + dataBundle.toString()); */ log.i("NotificationService StandardUI jobScheduled: " + jobId); }
private void processRecommendationImage(StatusBarNotification sbn) { if (RecommendationsUtil.isRecommendation(sbn)) { Bitmap img; Notification notif = sbn.getNotification(); boolean partner = RecommendationsUtil.isInPartnerRow(this.mContext, sbn); if (notif.largeIcon != null) { img = notif.largeIcon; } else { img = getRecomendationImage(sbn.getKey()); } // notif.extras.remove("android.largeIcon"); if (img == null) { return; } if (partner) { notif.largeIcon = getResizedRecommendationBitmap(img, true, false); return; } Point dim = getResizedCardDimensions(img.getWidth(), img.getHeight()); if (dim != null) { notif.extras.putInt("notif_img_width", dim.x); notif.extras.putInt("notif_img_height", dim.y); } notif.largeIcon = getResizedRecommendationBitmap(img, false, true); } }
protected void processRecommendationImage(StatusBarNotification sbn) { if (RecommendationsUtil.isRecommendation(sbn)) { Notification notif = sbn.getNotification(); boolean partner = RecommendationsUtil.isInPartnerRow(this.mContext, sbn); Bitmap img = notif.largeIcon != null ? notif.largeIcon : getRecomendationImage(sbn.getKey()); notif.extras.remove("android.largeIcon"); if (img != null) { if (partner) { notif.largeIcon = getResizedRecommendationBitmap(img, true, false); } else { Point dim = getResizedCardDimensions(img.getWidth(), img.getHeight()); if (dim != null) { notif.extras.putInt("notif_img_width", dim.x); notif.extras.putInt("notif_img_height", dim.y); } notif.largeIcon = getResizedRecommendationBitmap(img, false, true); } } } }
private void openNotification(int id) { StatusBarNotification sbn = mNotificationArray.get(id); if(sbn != null){ try { sbn.getNotification().contentIntent.send(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cancelNotification(sbn.getKey()); } cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId()); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } } mNotificationArray.remove(id); }
public void fetchExistingNotifications() { final StatusBarNotification[] snotifications = getActiveNotifications(); /* Get rid of any recommendations already ruined by Amazon's hand... */ for (StatusBarNotification sbn : snotifications) { Notification notification = sbn.getNotification(); if (notification.largeIcon == null) { cancelNotification(sbn.getKey()); } } onFetchExistingNotifications(getActiveNotifications()); // 1 }
Log.d(Constants.TAG, "NotificationUtils replyToNotification key: " + statusBarNotification.getKey());
private boolean shouldBeFilteredOut(StatusBarNotification sbn) { Notification notification = sbn.getNotification(); if (AndroidVersion.isAtLeastOreo()) { getCurrentRanking().getRanking(sbn.getKey(), mTempRanking); if (!mTempRanking.canShowBadge()) { return true; } if (mTempRanking.getChannel().getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID)) { // Special filtering for the default, legacy "Miscellaneous" channel. if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) { return true; } } } if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) { return true; } boolean isGroupHeader = (notification.flags & Notification.FLAG_GROUP_SUMMARY) != 0; CharSequence title = notification.extras.getCharSequence(Notification.EXTRA_TITLE); CharSequence text = notification.extras.getCharSequence(Notification.EXTRA_TEXT); boolean missingTitleAndText = TextUtils.isEmpty(title) && TextUtils.isEmpty(text); return (isGroupHeader || missingTitleAndText); }
final String key = statusBarNotification.getKey();
log.d("notificationRemoved: %s", statusBarNotification.getKey()); dataBundle.putParcelable("data", StatusBarNotificationData.from(this, statusBarNotification, false)); NotificationStore.addStandardNotification(statusBarNotification.getKey(), dataBundle); int id = NotificationJobService.NOTIFICATION_REMOVED; int jobId = id + abs((int) (long) (statusBarNotification.getId() % 10000L)); scheduleJob(id, jobId, statusBarNotification.getKey()); dataBundle.putParcelable("data", StatusBarNotificationData.from(this, sbn, false)); NotificationStore.addStandardNotification(statusBarNotification.getKey(), dataBundle); scheduleJob(id, jobId, statusBarNotification.getKey());
Icon icon = null; packageUserKey = PackageUserKey.fromNotification(statusBarNotification); notificationKey = statusBarNotification.getKey(); Notification notification = statusBarNotification.getNotification(); title = notification.extras.getCharSequence(Notification.EXTRA_TITLE);
private void sendNotificationWithCustomUI(byte filterResult, StatusBarNotification statusBarNotification) { final String key = statusBarNotification.getKey(); NotificationData notificationData = NotificationFactory.fromStatusBarNotification(this, statusBarNotification); notificationsAvailableToReply.put(notificationData.getKey(), statusBarNotification); if (isStandardDisabled()) { notificationData.setVibration(getDefaultVibration()); } else notificationData.setVibration(0); notificationData.setHideButtons(true); notificationData.setForceCustom(false); if (filterResult == Constants.FILTER_LOCALOK) notificationData.setHideReplies(true); else notificationData.setHideReplies(false); NotificationStore.addCustomNotification(key, notificationData); NotificationStore.addNotificationBundle(key, statusBarNotification.getNotification().extras); int id = NotificationJobService.NOTIFICATION_POSTED_CUSTOM_UI; int jobId = id + abs((int) (long) (statusBarNotification.getId() % 10000L)); scheduleJob(id, jobId, key); /* * Disabled while testing JobScheduler * extractImagesFromNotification(statusBarNotification, notificationData); Watch.get().postNotification(notificationData); */ log.i("NotificationService CustomUI jobScheduled: " + jobId); }