@Override public void onNotificationPosted(StatusBarNotification sbn) { Bundle extras = sbn.getNotification().extras; packageName = sbn.getPackageName(); Object oTitle = extras.get(Notification.EXTRA_TITLE); Object oText = extras.get(Notification.EXTRA_TEXT); if (oTitle == null || oText == null) return; title = oTitle.toString(); text = oText.toString(); Log.d(TAG, "Notification - : " + " \npackageName: " + packageName + " \nTitle : " + title + " \nText : " + text); switch (packageName) { case pkgWX: new WXClient(getApplicationContext()).onNotification(title, text); break; case pkgThis: App.timeCheckNotificationListenerServiceIsWorking = new Date().getTime(); Log.i(TAG, "onNotificationPosted: time: " + App.timeCheckNotificationListenerServiceIsWorking); break; } }
@Implementation(minSdk = M) public StatusBarNotification[] getActiveNotifications() { StatusBarNotification[] statusBarNotifications = new StatusBarNotification[notifications.size()]; int i = 0; for (Map.Entry<Key, Notification> entry : notifications.entrySet()) { statusBarNotifications[i++] = new StatusBarNotification( RuntimeEnvironment.application.getPackageName(), null /* opPkg */, entry.getKey().id, entry.getKey().tag, android.os.Process.myUid() /* uid */, android.os.Process.myPid() /* initialPid */, 0 /* score */, entry.getValue(), android.os.Process.myUserHandle(), 0 /* postTime */); } return statusBarNotifications; }
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; }
log.d("notificationRemoved: %s", statusBarNotification.getKey()); if (isPackageAllowed(statusBarNotification.getPackageName()) && (!NotificationCompat.isGroupSummary(statusBarNotification.getNotification())) && (!((statusBarNotification.getNotification().flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT))) { NotificationStore.addStandardNotification(statusBarNotification.getKey(), dataBundle); int id = NotificationJobService.NOTIFICATION_REMOVED; int jobId = id + abs((int) (long) (statusBarNotification.getId() % 10000L)); scheduleJob(id, jobId, statusBarNotification.getKey()); if (grouped_notifications.containsKey(statusBarNotification.getId())) { int[] grouped = grouped_notifications.get(statusBarNotification.getId()); for (int i : grouped) { int nextId = abs((int) (long) (statusBarNotification.getId() % 10000L)) + i; Log.d(Constants.TAG, "NotificationService onNotificationRemoved grouped id: " + nextId); dataBundle = new DataBundle(); StatusBarNotification sbn = new StatusBarNotification(statusBarNotification.getPackageName(), "", nextId, statusBarNotification.getTag(), 0, 0, 0, statusBarNotification.getNotification(), statusBarNotification.getUser(), statusBarNotification.getPostTime()); dataBundle.putParcelable("data", StatusBarNotificationData.from(this, sbn, false)); NotificationStore.addStandardNotification(statusBarNotification.getKey(), dataBundle); scheduleJob(id, jobId, statusBarNotification.getKey());
private static List<Notification> asNotificationList( StatusBarNotification[] statusBarNotifications) { List<Notification> notificationList = new ArrayList<>(statusBarNotifications.length); for (StatusBarNotification statusBarNotification : statusBarNotifications) { notificationList.add(statusBarNotification.getNotification()); } return notificationList; } }
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); } } }
@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()); }
@Override public void onNotificationPosted(StatusBarNotification sbn) { Log.i(TAG, "onNotificationPosted"); Log.i(TAG, "ID :" + sbn.getId() + "\t" + sbn.getNotification().tickerText + "\t" + sbn.getPackageName()); }
@TargetApi(18) public NotificationData(StatusBarNotification sbn, String key) { this.key = key; init(sbn.getNotification(), sbn.getId(), sbn.getPackageName()); isOngoing = sbn.isOngoing(); }
notificationTimeGone = new HashMap<>(); String notificationPackage = statusBarNotification.getPackageName(); String notificationId = statusBarNotification.getKey(); Notification notification = statusBarNotification.getNotification(); String text = ""; int flags = 0; CharSequence bigText = (statusBarNotification.getNotification().extras).getCharSequence(Notification.EXTRA_TEXT); if (bigText != null) { text = bigText.toString();
if(notifies[i].isClearable()){ if(notifies[i].getPackageName().equals(sbn.getPackageName()) && notifies[i].getId()==sbn.getId()){ if(validSbn != null && mNotifyPkgList.contains(validSbn.getPackageName()) && !validSbn.getPackageName().equals("android") && validSbn.getNotification().contentIntent != null){ StatusBarNotification notify = mNotificationArray.get(validSbn.getId()); mNotificationArray.put(validSbn.getId(),validSbn); Icon icon = validSbn.getNotification().getLargeIcon(); String title = sbn.getNotification().extras.getString("android.title");
private RepliableNotification extractRepliableNotification(StatusBarNotification statusBarNotification) { RepliableNotification repliableNotification = new RepliableNotification(); if (statusBarNotification != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try { if (statusBarNotification.getNotification().actions != null) { for (Notification.Action act : statusBarNotification.getNotification().actions) { if (act != null && act.getRemoteInputs() != null) { // Is a reply repliableNotification.remoteInputs.addAll(Arrays.asList(act.getRemoteInputs())); repliableNotification.pendingIntent = act.actionIntent; break; } } repliableNotification.packageName = statusBarNotification.getPackageName(); repliableNotification.tag = statusBarNotification.getTag();//TODO find how to pass Tag with sending PendingIntent, might fix Hangout problem } } catch (Exception e) { Log.w("NotificationPlugin", "problem extracting notification wear for " + statusBarNotification.getNotification().tickerText); e.printStackTrace(); } } } return repliableNotification; }
private boolean isBlacklisted(StatusBarNotification sbn) { return blacklistedApp.contains(sbn.getPackageName()); }
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()); } }
Icon icon = null; packageUserKey = PackageUserKey.fromNotification(statusBarNotification); notificationKey = statusBarNotification.getKey(); Notification notification = statusBarNotification.getNotification(); title = notification.extras.getCharSequence(Notification.EXTRA_TITLE); text = notification.extras.getCharSequence(Notification.EXTRA_TEXT); Resources res = context.getPackageManager().getResourcesForApplication(statusBarNotification.getPackageName()); if (AndroidVersion.isAtLeastMarshmallow) { mIconDrawable = notification.getSmallIcon().loadDrawable(context); mIconDrawable = res.getDrawable(notification.icon, context.getTheme()); mIconColor = statusBarNotification.getNotification().color; mIsIconLarge = false; } catch (PackageManager.NameNotFoundException e) { mIconDrawable = new BitmapDrawable(context.getResources(), LauncherAppState .getInstance(context).getIconCache() .getDefaultIcon(statusBarNotification.getUser())); mBadgeIcon = 0;
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)); } }
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); }
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 void scoreAndInsertRecommendationAdd(StatusBarNotification sbn, List<RecOperation> changes) { this.mRanker.prepNormalizationValues(); String pkg = sbn.getPackageName(); this.mRanker.markPostedRecommendations(pkg); if (!this.mRanker.isBlacklisted(pkg)) { wantPosition++; } else { this.mNotificationResolver.cancelRecommendation(sbn.getKey()); return;
boolean shouldFilterOut(StatusBarNotification sbn) { if (!(mEnvironment.isDeviceProvisioned() || showNotificationEvenIfUnprovisioned(sbn))) { return true; } if (!mEnvironment.isNotificationForCurrentProfiles(sbn)) { return true; } if (sbn.getNotification().visibility == Notification.VISIBILITY_SECRET && mEnvironment.shouldHideSensitiveContents(sbn.getUserId())) { return true; } return false; }