private void cancelAlarmNotification(Context context) { NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { StatusBarNotification[] activeNotifications = mNotifyMgr.getActiveNotifications(); for (StatusBarNotification notification : activeNotifications) { if (notification.getId() == ALARM_NOTIFICATION_ID) mNotifyMgr.cancel(ALARM_NOTIFICATION_ID); } } else mNotifyMgr.cancel(ALARM_NOTIFICATION_ID); }
public void notifyNewNotify(StatusBarNotification sbn, Parcelable icon) { Intent intent = new Intent(); intent.putExtra("what",Config.NEW_NOTIFICATION); intent.putExtra("notifyId",sbn.getId()); intent.putExtra("pkg",sbn.getPackageName()); if(icon != null)intent.putExtra("icon",icon); intent.setClass(this, FloatService.class); startService(intent); }
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()); } }
@RequiresApi(api = Build.VERSION_CODES.KITKAT) @Override public void onNotificationRemoved(StatusBarNotification sbn) { if(mNotificationArray.indexOfKey(sbn.getId()) != -1){ mNotificationArray.remove(sbn.getId()); notifyCancelNotify(sbn.getId()); } try { String title = sbn.getNotification().extras.getString("android.title"); if (title == null) return; if(sKeyboardTitleList.contains(title)){ if(sp.getBoolean("floatSwitch",false)){ sendMsg(Config.FLOAT_AUTOMOVE, "move", false); } } }catch (Exception e){ e.printStackTrace(); } }
public static boolean equals(StatusBarNotification left, StatusBarNotification right) { boolean z = true; if (left != null && right != null) { return TextUtils.equals(left.getPackageName(), right.getPackageName()) && left.getId() == right.getId() && TextUtils.equals(left.getTag(), right.getTag()); } else { if (left != right) { z = false; } return z; } }
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; }
public static boolean equals(StatusBarNotification left, StatusBarNotification right) { boolean z = true; if (left == null || right == null) { if (left != right) { z = false; } return z; } else if (TextUtils.equals(left.getPackageName(), right.getPackageName()) && left.getId() == right.getId() && TextUtils.equals(left.getTag(), right.getTag())) { return true; } else { return false; } }
public void testCheckNotification_2() throws IOException, InterruptedException, GcmException { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { GcmResponse gcmResponse = endPointImp.sendGcmMulticastRequestImp(getGcmMultiRequest()); assertThat(gcmResponse.getSuccess(), is(1)); Thread.sleep(2000); assertThat(mManager.getActiveNotifications().length, is(1)); StatusBarNotification barNotification = mManager.getActiveNotifications()[0]; assertThat(barNotification.getId(), is(INCIDENCIA.getTitleRsc())); // We check the pending intent. PendingIntent pendingIntent = barNotification.getNotification().contentIntent; assertThat(pendingIntent.getCreatorPackage(), is(GcmRequest.PACKAGE_DIDEKINDROID)); } }
@Override public void onNotificationPosted(StatusBarNotification sbn) { Log.i(TAG, "onNotificationPosted"); Log.i(TAG, "ID :" + sbn.getId() + "\t" + sbn.getNotification().tickerText + "\t" + sbn.getPackageName()); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public class MyNotificationListenerService extends NotificationListenerService {...} ... private void clearNotificationExample(StatusBarNotification sbn) { myNotificationListenerService.cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId()); }
public static LeanbackProto$LeanbackEvent logRecommendationInsertAction(StatusBarNotification notification, double rawScore, double score, int position, Context context) { if (Log.isLoggable(TAG, 2)) { Log.v(TAG, "Log recommendation insert event"); } LeanbackProto$LeanbackEvent leanbackEvent = new LeanbackProto$LeanbackEvent(); leanbackEvent.type = Integer.valueOf(4); leanbackEvent.timestamp = Long.valueOf(System.currentTimeMillis() * 1000); LeanbackProto$RecommendationInsertAction insertAction = new LeanbackProto$RecommendationInsertAction(); insertAction.position = Integer.valueOf(position); insertAction.packageName = notification.getPackageName(); insertAction.tagName = notification.getTag(); insertAction.bucketId = Integer.valueOf(notification.getId()); insertAction.unnormalizedPriority = Integer.valueOf(notification.getNotification().priority); insertAction.normalizedPriority = Float.valueOf((float) rawScore); insertAction.score = Float.valueOf((float) score); leanbackEvent.recommendationInsertAction = insertAction; log(leanbackEvent, context); return leanbackEvent; }
private void clearNotificationExample(StatusBarNotification sbn) { myNotificationListenerService.cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId()); }
public static LeanbackProto$LeanbackEvent logRecommendationRankEvent(List<StatusBarNotification> notifications, Map<StatusBarNotification, Double> rawScoreMap, Map<StatusBarNotification, Double> scoreMap, Context context) { if (Log.isLoggable(TAG, 2)) { Log.v(TAG, "Log reccomendation rank event"); } LeanbackProto$LeanbackEvent leanbackEvent = new LeanbackProto$LeanbackEvent(); leanbackEvent.recommendationRankAction = new LeanbackProto$RecommendationRankAction(); leanbackEvent.type = Integer.valueOf(2); leanbackEvent.timestamp = Long.valueOf(System.currentTimeMillis() * 1000); LeanbackProto$Recommendation[] recs = new LeanbackProto$Recommendation[notifications.size()]; for (int i = 0; i < notifications.size(); i++) { StatusBarNotification notification = (StatusBarNotification) notifications.get(i); LeanbackProto$Recommendation recommendation = new LeanbackProto$Recommendation(); recommendation.position = Integer.valueOf(i); recommendation.packageName = notification.getPackageName(); recommendation.tagName = notification.getTag(); recommendation.bucketId = Integer.valueOf(0); recommendation.notificationId = Integer.valueOf(notification.getId()); recommendation.unnormalizedPriority = Integer.valueOf(notification.getNotification().priority); recommendation.normalizedPriority = Float.valueOf((float) ((Double) rawScoreMap.get(notification)).doubleValue()); recommendation.score = Float.valueOf((float) ((Double) scoreMap.get(notification)).doubleValue()); recs[i] = recommendation; } leanbackEvent.recommendationRankAction.recommendations = recs; log(leanbackEvent, context); return leanbackEvent; }
@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()); } } } }
@TargetApi(18) public NotificationData(StatusBarNotification sbn, String key) { this.key = key; init(sbn.getNotification(), sbn.getId(), sbn.getPackageName()); isOngoing = sbn.isOngoing(); }
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); }
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 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); }
int id = n.getId(); String key = ""; String title = "";