List of usage examples for android.service.notification StatusBarNotification getPackageName
public String getPackageName()
From source file:com.cyanogenmod.messaging.quickmessage.QuickMessagePopup.java
/** * Clears the status bar notification and, optionally, mark all messages as read * This is used to clean up when we are done with all qm's * * @param markAsRead - should remaining qm's be maked as read? *//* w w w . j a v a 2s . c o m*/ private void clearNotification(boolean markAsRead) { // Dismiss the notification that brought us here. NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); StatusBarNotification[] statusBarNotifications = notificationManager.getActiveNotifications(); final String packageName = getPackageName(); for (StatusBarNotification statusBarNotification : statusBarNotifications) { if (packageName.equals(statusBarNotification.getPackageName())) { notificationManager.cancel(statusBarNotification.getTag(), statusBarNotification.getId()); break; } } // Mark all contained conversations as seen if (markAsRead) { markAllMessagesRead(); } // Clear the messages list mMessageList.clear(); if (DEBUG) Log.d(LOG_TAG, "clearNotification(): Message list cleared. Size = " + mMessageList.size()); }
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;//from w w w. ja v a 2 s . co m // 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:org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationsPlugin.java
public void sendNotification(StatusBarNotification statusBarNotification, boolean requestAnswer) { Notification notification = statusBarNotification.getNotification(); AppDatabase appDatabase = new AppDatabase(context); if ((notification.flags & Notification.FLAG_FOREGROUND_SERVICE) != 0 || (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0 || (notification.flags & Notification.FLAG_LOCAL_ONLY) != 0) { //This is not a notification we want! return;//from w w w .j a v a 2 s . c om } appDatabase.open(); if (!appDatabase.isEnabled(statusBarNotification.getPackageName())) { return; // we dont want notification from this app } appDatabase.close(); String key = getNotificationKeyCompat(statusBarNotification); String packageName = statusBarNotification.getPackageName(); String appName = AppsHelper.appNameLookup(context, packageName); if ("com.facebook.orca".equals(packageName) && (statusBarNotification.getId() == 10012) && "Messenger".equals(appName) && notification.tickerText == null) { //HACK: Hide weird Facebook empty "Messenger" notification that is actually not shown in the phone return; } if (packageName.equals("com.google.android.googlequicksearchbox")) { //HACK: Hide Google Now notifications that keep constantly popping up (and without text because we don't know how to read them properly) return; } NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_NOTIFICATION); if (packageName.equals("org.kde.kdeconnect_tp")) { //Make our own notifications silent :) np.set("silent", true); np.set("requestAnswer", true); //For compatibility with old desktop versions of KDE Connect that don't support "silent" } /* if (sendIcons) { try { Drawable drawableAppIcon = AppsHelper.appIconLookup(context, packageName); Bitmap appIcon = ImagesHelper.drawableToBitmap(drawableAppIcon); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); if (appIcon.getWidth() > 128) { appIcon = Bitmap.createScaledBitmap(appIcon, 96, 96, true); } appIcon.compress(Bitmap.CompressFormat.PNG, 90, outStream); byte[] bitmapData = outStream.toByteArray(); np.setPayload(bitmapData); } catch (Exception e) { e.printStackTrace(); Log.e("NotificationsPlugin", "Error retrieving icon"); } } */ np.set("id", key); np.set("appName", appName == null ? packageName : appName); np.set("isClearable", statusBarNotification.isClearable()); np.set("ticker", getTickerText(notification)); np.set("time", Long.toString(statusBarNotification.getPostTime())); if (requestAnswer) { np.set("requestAnswer", true); np.set("silent", true); } device.sendPackage(np); }