List of usage examples for android.service.notification StatusBarNotification getNotification
public Notification getNotification()
From source file:gowtham.com.desknote.MyListener.java
@Override public void onNotificationPosted(StatusBarNotification sbn) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); // If user has disabled notifications, then skip if (!pref.getBoolean("send_notifications", false)) return;// w w w .ja v a 2 s . c om // Look for our device Set<String> emptySet = new HashSet<String>(); Collection<String> addresses = pref.getStringSet("desktop_address", emptySet); Log.i(MainActivity.TAG, "Connected devices " + connectedDevices); Collection<String> connectedAddresses = getConnectedAddresses(addresses, connectedDevices); Notification mNotification = sbn.getNotification(); // Can't do much if we get a null! if (mNotification == null) return; Bundle extras = mNotification.extras; String packageName = sbn.getPackageName(); String title = extras.getString(Notification.EXTRA_TITLE); String text = extras.getString(Notification.EXTRA_TEXT); String subText = extras.getString(Notification.EXTRA_SUB_TEXT); Integer smallIconID = extras.getInt(Notification.EXTRA_SMALL_ICON); String icon = "null"; if (pref.getBoolean("include_images", false)) { if (extras.getParcelable(Notification.EXTRA_LARGE_ICON) != null) { Bitmap b = Bitmap.class.cast(extras.getParcelable(Notification.EXTRA_LARGE_ICON)); icon = bitmap2Base64(b); } else { icon = getIcon(packageName, smallIconID); } } Map<String, String> extrasMap = new HashMap<String, String>(); for (String key : extras.keySet()) { extrasMap.put(key, String.valueOf(extras.get(key))); } Log.e(MainActivity.TAG, "Got a new notification " + title + " " + mNotification.hashCode()); Message msg = new Message(title, text, subText, icon, mNotification.toString(), extrasMap, packageName); NotificationTransmitter tx = new NotificationTransmitter(); Log.e(MainActivity.TAG, "Sending bluetooth message"); tx.transmit(connectedAddresses, msg); }
From source file:com.yangtsaosoftware.pebblemessenger.services.NotificationService.java
@Override public void onNotificationPosted(StatusBarNotification sbn) { if (sbn == null) return;//from w w w . j av a2s . c o 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."); } }