List of usage examples for android.service.notification StatusBarNotification getTag
public String getTag()
From source file:com.achep.acdisplay.notifications.NotificationUtils.java
public static boolean equals(StatusBarNotification n, StatusBarNotification n2) { return n == n2 || n != null && n2 != null && new EqualsBuilder().append(n.getId(), n2.getId()) .append(n.getPackageName(), n2.getPackageName()).append(n.getTag(), n2.getTag()).isEquals(); }
From source file:com.oasisfeng.nevo.StatusBarNotificationEvo.java
public static StatusBarNotificationEvo from(final StatusBarNotification sbn) { if (sbn instanceof StatusBarNotificationEvo) return (StatusBarNotificationEvo) sbn; return new StatusBarNotificationEvo(sbn.getPackageName(), null, sbn.getId(), sbn.getTag(), getUid(sbn), 0, 0, sbn.getNotification(), getUser(sbn), sbn.getPostTime()); }
From source file:org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationsPlugin.java
public static String getNotificationKeyCompat(StatusBarNotification statusBarNotification) { String result;/* w w w . j a v a 2 s . co m*/ // 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; }
From source file:com.ademsha.appnotifico.NotificationDataHelper.java
public static JSONObject getStatusBarNotificationDataAsJSON(StatusBarNotification statusBarNotification) { JSONObject notification = new JSONObject(); try {/*from w ww.j a v a2 s . com*/ notification.put("id", String.valueOf(statusBarNotification.getId()).replace("null", "")); notification.put("ticker_text", String.valueOf(statusBarNotification.getNotification().tickerText).replace("null", "")); notification.put("priority", String.valueOf(statusBarNotification.getNotification().priority).replace("null", "")); notification.put("number", String.valueOf(statusBarNotification.getNotification().number).replace("null", "")); notification.put("tag", String.valueOf(statusBarNotification.getTag()).replace("null", "")); notification.put("posted_at", String.valueOf(statusBarNotification.getPostTime()).replace("null", "")); notification.put("source", String.valueOf(statusBarNotification.getPackageName()).replace("null", "")); notification.put("when", String.valueOf(statusBarNotification.getNotification().when).replace("null", "")); notification.put("led_argb", String.valueOf(statusBarNotification.getNotification().ledARGB).replace("null", "")); notification.put("led_OnMS", String.valueOf(statusBarNotification.getNotification().ledOnMS).replace("null", "")); notification.put("led_OnMS", String.valueOf(statusBarNotification.getNotification().ledOffMS).replace("null", "")); notification.put("vibrate", Arrays.toString(statusBarNotification.getNotification().vibrate).replace("null", "")); if (statusBarNotification.getNotification().sound != null) { notification.put("sound", String.valueOf(statusBarNotification.getNotification().sound.getPath())); } notification.put("action_intent_package", String.valueOf(statusBarNotification.getNotification().contentIntent.getCreatorPackage())); notification.put("action_intent_uid", String.valueOf(statusBarNotification.getNotification().contentIntent.getCreatorUid())); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notification.put("visibility", String.valueOf(statusBarNotification.getNotification().visibility)); notification.put("color", String.valueOf(statusBarNotification.getNotification().color)); notification.put("category", String.valueOf(statusBarNotification.getNotification().category)); notification.put("user", String.valueOf(statusBarNotification.getUser().toString())); notification.put("group_key", String.valueOf(statusBarNotification.getGroupKey())); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { notification.put("key", String.valueOf(statusBarNotification.getKey())); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { notification = getNotificationExtras(notification, statusBarNotification); } } catch (JSONException e) { e.printStackTrace(); } return notification; }
From source file:com.achep.acdisplay.notifications.OpenNotificationJellyBeanMR2.java
/** * {@inheritDoc}/* w w w . j a v a 2 s . c om*/ */ @Override public boolean hasIdenticalIds(@Nullable OpenNotification n) { if (n == null) return false; StatusBarNotification sbn = getStatusBarNotification(); StatusBarNotification sbn2 = n.getStatusBarNotification(); assert sbn2 != null; return new EqualsBuilder().append(sbn.getId(), sbn2.getId()).append(getPackageName(), n.getPackageName()) .append(sbn.getTag(), sbn2.getTag()).isEquals(); }
From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java
@Override public void onListenerConnected() { super.onListenerConnected(); Log.d(TAG, "listener connected"); //bootstrapping the notification map StatusBarNotification[] nArray = this.getActiveNotifications(); if (nArray != null) { for (StatusBarNotification sbn : nArray) if (!SERVICE_NOTIFICATION.equals(sbn.getTag())) handlePostedNotification(sbn); }/* w w w . ja v a2 s .c o m*/ }
From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java
@Override public void onNotificationPosted(StatusBarNotification sbn) { super.onNotificationPosted(sbn); if (!SERVICE_NOTIFICATION.equals(sbn.getTag())) handlePostedNotification(sbn);/*from w w w . ja v a 2s . co m*/ }
From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java
@Override public void onNotificationRemoved(StatusBarNotification sbn) { super.onNotificationRemoved(sbn); if (!SERVICE_NOTIFICATION.equals(sbn.getTag())) handleRemovedNotification(sbn);/* w ww. j a va 2 s .c om*/ }
From source file:com.yangtsaosoftware.pebblemessenger.services.NotificationService.java
@Override public void onNotificationPosted(StatusBarNotification sbn) { if (sbn == null) return;/*from w ww . j ava2 s . co m*/ Constants.log(LOG_TAG, "New Access Event:" + sbn.getPackageName() + " tag:" + sbn.getTag()); /*if(event.getEventType()!= AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED){ return; } */ PowerManager powMan = (PowerManager) this.getSystemService(POWER_SERVICE); if (!notifScreenOn && powMan.isScreenOn()) { Constants.log(LOG_TAG, "because screen out!"); return; } //Parcelable parcelable=event.getParcelableData(); //if(!(parcelable instanceof Notification)) return; Notification notif = sbn.getNotification(); if (sbn.isOngoing()) { Constants.log(LOG_TAG, "because is Ongoing!"); return; } String eventPackageName; if (sbn.getPackageName() != null) { eventPackageName = sbn.getPackageName(); } else { Constants.log(LOG_TAG, "Can't get event package name. Returning."); return; } boolean found = false; for (String packageName : packages) { if (packageName.equalsIgnoreCase(eventPackageName)) { found = true; break; } } if (!found) { Constants.log(LOG_TAG, eventPackageName + " was not found in the include list. Returning."); return; } String title = eventPackageName.substring(eventPackageName.lastIndexOf('.') + 1); // get the notification text Bundle notiBundle = notif.extras; StringBuilder notifySb = new StringBuilder(); CharSequence notifyChars = notiBundle.getCharSequence(Notification.EXTRA_TITLE); if (notifyChars != null) { notifySb.append(notifyChars); } else { Constants.log(LOG_TAG, "empty message title,return!"); return; } CharSequence bodyCS = notiBundle.getCharSequence(Notification.EXTRA_TEXT); if (bodyCS != null) { notifySb.append(":"); notifySb.append(bodyCS); } else { Constants.log(LOG_TAG, "empty message body,return!" + notifySb.toString()); return; } bodyCS = notiBundle.getCharSequence(Notification.EXTRA_SUB_TEXT); if (bodyCS != null) { notifySb.append(bodyCS); } Message msg = Message.obtain(); msg.what = MessageProcessingService.MSG_NEW_MESSAGE; Bundle b = new Bundle(); b.putString(MessageDbHandler.COL_MESSAGE_APP, title); b.putString(MessageDbHandler.COL_MESSAGE_CONTENT, notifySb.toString()); Constants.log(LOG_TAG, "Send new message title:" + title + " body:" + notifySb.toString()); msg.setData(b); try { rMessageProcessHandler.send(msg); } catch (RemoteException e) { e.printStackTrace(); Constants.log(LOG_TAG, "Error when sending message to MessageProcessingService."); } }
From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java
/** * helper class, cancels given notification from system. Should be compatible with all android versions * @param sbn the notification to cancel *///from w ww. j a va2 s .c o m @SuppressWarnings("deprecation") public void cancelNotification(StatusBarNotification sbn) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) super.cancelNotification(sbn.getKey()); else super.cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId()); }