Java Code Examples for android.service.notification.StatusBarNotification#getPackageName()
The following examples show how to use
android.service.notification.StatusBarNotification#getPackageName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotificationPiggyback.java From Slide with GNU General Public License v3.0 | 6 votes |
@Override public void onNotificationPosted(StatusBarNotification sbn) { final String packageName = sbn.getPackageName(); if (!TextUtils.isEmpty(packageName) && packageName.equals("com.reddit.frontpage")) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cancelNotification(sbn.getKey()); } else { cancelNotification(packageName, sbn.getTag(), sbn.getId()); } Intent alarmIntent = new Intent(getApplicationContext(), CheckForMailSingle.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, alarmIntent, 0); AlarmManager manager = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); manager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 100, pendingIntent); } }
Example 2
Source File: NotificationListener.java From things-notification with Apache License 2.0 | 6 votes |
@Override public void onNotificationPosted(StatusBarNotification sbn) { Log.d(TAG, "Notification received: "+sbn.getPackageName()+":"+sbn.getNotification().tickerText); if (sbn.getNotification().tickerText == null) { return; } WritableNativeMap params = new WritableNativeMap(); params.putString("text", sbn.getNotification().tickerText.toString()); String app = sbn.getPackageName(); if (app.equals(NotificationModule.smsApp)) { params.putString("app", "sms"); } else { params.putString("app", app); } NotificationModule.sendEvent("notificationReceived", params); }
Example 3
Source File: NotificationUpdateService.java From deskcon-android with GNU General Public License v3.0 | 6 votes |
@Override public void onNotificationPosted(StatusBarNotification not) { // permissions boolean send_other_notifications = sharedPrefs.getBoolean("send_other_notifications", false); ArrayList<String> whitelist = getNotificationWhitelist(); String packagename = not.getPackageName(); if (send_other_notifications && whitelist.contains(packagename)) { Log.d("Notification: ", "new post"); Notification notification = not.getNotification(); String text = getAppnameFromPackagename(packagename) + " " + notification.tickerText.toString(); startUpdateServiceCommand(text); } }
Example 4
Source File: Notification.java From Pi-Locker with GNU General Public License v2.0 | 6 votes |
@Override public void onNotificationPosted(StatusBarNotification sbn) { Bundle extras = sbn.getNotification().extras; String title = extras.getString("android.title"); String text = extras.getCharSequence("android.text").toString(); String pack = sbn.getPackageName(); CharSequence ticker = sbn.getNotification().tickerText; boolean ongoing = sbn.isOngoing(); boolean clearable = sbn.isClearable(); Intent msgrcv = new Intent("Msg"); msgrcv.putExtra("title", title); msgrcv.putExtra("text", text); msgrcv.putExtra("p", pack); msgrcv.putExtra("c", clearable); msgrcv.putExtra("o", ongoing); msgrcv.putExtra("t", String.valueOf(ticker)); LocalBroadcastManager.getInstance(context).sendBroadcast(msgrcv); }
Example 5
Source File: NLService.java From fitnotifications with Apache License 2.0 | 6 votes |
@Override public void onNotificationPosted(StatusBarNotification sbn, NotificationListenerService.RankingMap rankingMap) { if (mForwardOnlyPriorityNotifs) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && mInterruptionFilter == INTERRUPTION_FILTER_PRIORITY) { String packageName = sbn.getPackageName(); String rankingKey = null; for (String s : rankingMap.getOrderedKeys()) { if (s.contains(packageName)) { rankingKey = s; break; } } Ranking ranking = new Ranking(); if (rankingKey != null && rankingMap.getRanking(rankingKey, ranking)) { if (!ranking.matchesInterruptionFilter()) { return; } } } } onNotificationPosted(sbn); }
Example 6
Source File: NotificationListenerService.java From heads-up with GNU General Public License v3.0 | 6 votes |
public boolean isNotificationValid(String pkg, String tag, int id) { final StatusBarNotification[] activeNotifications = getActiveNotifications(); for (StatusBarNotification statusBarNotification : activeNotifications) { final String statusBarNotificationTag = statusBarNotification.getTag(); final String statusBarNotificationPackageName = statusBarNotification.getPackageName(); final int statusBarNotificationId = statusBarNotification.getId(); if (statusBarNotificationPackageName.equals(pkg) && statusBarNotificationId == id) { if (tag == null && statusBarNotificationTag == null) return true; if (tag != null && statusBarNotificationTag != null) if (statusBarNotificationTag.equals(tag)) return true; } } return false; }
Example 7
Source File: NotificationListener.java From MiPushFramework with GNU General Public License v3.0 | 6 votes |
private boolean checkAppSwitch(OnlineConfig onlineConfig, StatusBarNotification statusBarNotification) { boolean z = true; String stringValue = onlineConfig.getStringValue(ConfigKey.CollectionNotificationInfoAppSwitch.getValue(), "b"); if (TextUtils.isEmpty(stringValue)) { return false; } List emptyList = Collections.emptyList(); if (stringValue.length() > 1) { emptyList = Arrays.asList(stringValue.substring(1).split(";")); } String packageName = statusBarNotification.getPackageName(); char charAt = stringValue.charAt(0); if (charAt != 'b') { return charAt == 'w' ? emptyList.contains(packageName) : false; } else { if (emptyList.contains(packageName)) { z = false; } return z; } }
Example 8
Source File: NotificationListenerService.java From BaldPhone with Apache License 2.0 | 5 votes |
private void sendBroadcastToNotificationsActivity() { try { final StatusBarNotification[] statusBarNotifications = getActiveNotifications(); final Bundle[] bundlesToSend = new Bundle[statusBarNotifications.length]; for (int i = 0, statusBarNotificationsLength = statusBarNotifications.length; i < statusBarNotificationsLength; i++) { final StatusBarNotification statusBarNotification = statusBarNotifications[i]; final Notification notification = statusBarNotification.getNotification(); final Bundle bundle = bundlesToSend[i] = new Bundle(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { bundle.putParcelable("small_icon", notification.getSmallIcon()); bundle.putParcelable("large_icon", notification.getLargeIcon()); } else { bundle.putInt("small_icon", notification.icon); bundle.putParcelable("large_icon", notification.largeIcon); } bundle.putCharSequence("title", notification.extras.getCharSequence(Notification.EXTRA_TITLE)); bundle.putCharSequence("text", notification.extras.getCharSequence(Notification.EXTRA_TEXT)); bundle.putLong("time_stamp", notification.when); final CharSequence packageName = statusBarNotification.getPackageName(); bundle.putCharSequence("packageName", packageName); ApplicationInfo ai = null; try { ai = packageManager.getApplicationInfo(String.valueOf(packageName), 0); } catch (final PackageManager.NameNotFoundException ignore) { } bundle.putCharSequence("app_name", (ai != null ? packageManager.getApplicationLabel(ai) : "(unknown)")); bundle.putParcelable("clear_intent", notification.deleteIntent); bundle.putParcelable("content_intent", notification.contentIntent); bundle.putBoolean("clearable", (notification.flags & Notification.FLAG_NO_CLEAR) == 0); bundle.putBoolean("summery", (notification.flags & Notification.FLAG_GROUP_SUMMARY) == Notification.FLAG_GROUP_SUMMARY); bundle.putString(KEY_EXTRA_KEY, statusBarNotification.getKey()); } LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(NOTIFICATIONS_ACTIVITY_BROADCAST).putExtra(KEY_EXTRA_NOTIFICATIONS, bundlesToSend)); } catch (SecurityException e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); } }
Example 9
Source File: LockscreenAppBar.java From GravityBox with Apache License 2.0 | 5 votes |
@Override public void onNotificationDataChanged(final StatusBarNotification sbn) { for (AppInfo ai : mAppSlots) { if (ai.getPackageName() == null) continue; if (sbn == null || sbn.getPackageName() == null || sbn.getPackageName().equals(ai.getPackageName())) { ai.updateIcon(); } } }
Example 10
Source File: NotificationListenerService.java From NotificationBox with MIT License | 5 votes |
@Override public void onNotificationPosted(StatusBarNotification sbn) { super.onNotificationPosted(sbn); Log.d(TAG, "onNotificationPosted"); Notification notification = sbn.getNotification(); String packageName = sbn.getPackageName(); long time = sbn.getPostTime(); String title = notification.extras.getString(Notification.EXTRA_TITLE); String text = notification.extras.getString(Notification.EXTRA_TEXT); DbUtils.saveNotification(new NotificationInfo(packageName, title, text, time)); List<AppInfo> blackList = DbUtils.getApp(); for (AppInfo app : blackList) { if (packageName.equals(app.getPackageName())) { Log.d(TAG, packageName + " 拦截:" + title + ": " + text); if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) { cancelNotification(sbn.getKey()); } else { cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId()); } if (SettingUtils.getInstance().isNotify()) { createNotification(app.getAppName(), packageName, title, text); } } } }
Example 11
Source File: NotificationListener.java From Anti-recall with GNU Affero General Public License v3.0 | 5 votes |
@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; } }
Example 12
Source File: NotificationListener.java From always-on-amoled with GNU General Public License v3.0 | 4 votes |
private String getUniqueKey(StatusBarNotification notification) { return notification.getPackageName(); }
Example 13
Source File: StatusService.java From Status with Apache License 2.0 | 4 votes |
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()); }
Example 14
Source File: NLService.java From AsteroidOSSync with GNU General Public License v3.0 | 4 votes |
@Override public void onNotificationPosted(StatusBarNotification sbn) { Notification notification = sbn.getNotification(); String packageName = sbn.getPackageName(); String[] allowedOngoingApps = {"com.google.android.apps.maps"}; if((notification.priority < Notification.PRIORITY_DEFAULT) || ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0 && !Arrays.asList(allowedOngoingApps).contains(packageName)) || (NotificationCompat.getLocalOnly(notification)) || (NotificationCompat.isGroupSummary(notification))) return; NotificationParser notifParser = new NotificationParser(notification); String summary = notifParser.summary; String body = notifParser.body; int id = sbn.getId(); String appIcon = iconFromPackage.get(packageName); String appName = ""; try { final PackageManager pm = getApplicationContext().getPackageManager(); ApplicationInfo ai = pm.getApplicationInfo(packageName, 0); appName = pm.getApplicationLabel(ai).toString(); } catch (PackageManager.NameNotFoundException ignored) {} if(summary == null) summary = ""; else summary = summary.trim(); if(body == null) body = ""; else body = body.trim(); if(packageName == null) packageName = ""; if(appIcon == null) appIcon = ""; Intent i = new Intent("org.asteroidos.sync.NOTIFICATION_LISTENER"); i.putExtra("event", "posted"); i.putExtra("packageName", packageName); i.putExtra("id", id); i.putExtra("appName", appName); i.putExtra("appIcon", appIcon); i.putExtra("summary", summary); i.putExtra("body", body); sendBroadcast(i); }
Example 15
Source File: NotificationService.java From an2linuxclient with GNU General Public License v3.0 | 4 votes |
private boolean filter(StatusBarNotification sbn) { String packageName = sbn.getPackageName(); if (!globalEnabled() || !appEnabled(packageName)) { return false; } boolean usingCustomSettings = isUsingCustomSettings(packageName); SharedPreferences sp; if (usingCustomSettings) { sp = getSharedPreferences(getString(R.string.notification_settings_custom), MODE_PRIVATE); } else { sp = getSharedPreferences(getString(R.string.notification_settings_global), MODE_PRIVATE); } boolean isAn2linuxTestNotification = packageName.startsWith("kiwi.root.an2linuxclient"); if (dontSendIfScreenIsOn(sp, packageName, usingCustomSettings) && !isAn2linuxTestNotification) { boolean screenIsOn = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE); for (Display display : dm.getDisplays()) { if (display.getState() == Display.STATE_ON) { // private as in samsung always-on feature, not sure if this is how it works // https://stackoverflow.com/questions/2474367/how-can-i-tell-if-the-screen-is-on-in-android#comment71534994_17348755 boolean displayIsPrivate = (display.getFlags() & Display.FLAG_PRIVATE) == Display.FLAG_PRIVATE; if (!displayIsPrivate) { screenIsOn = true; break; } } } } else { PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); if (powerManager.isScreenOn()){ screenIsOn = true; } } if (screenIsOn) { return false; } } int flags = sbn.getNotification().flags; if (isOngoing(flags) && blockOngoing(sp, packageName, usingCustomSettings)){ return false; } if (isForeground(flags) && blockForeground(sp, packageName, usingCustomSettings)){ return false; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH){ if (isGroupSummary(flags) && blockGroupSummary(sp, packageName, usingCustomSettings)){ return false; } if (isLocalOnly(flags) && blockLocalOnly(sp, packageName, usingCustomSettings)){ return false; } } return priorityAllowed(sp, packageName, usingCustomSettings, sbn.getNotification().priority); }
Example 16
Source File: Notification.java From an2linuxclient with GNU General Public License v3.0 | 4 votes |
public Notification(StatusBarNotification sbn, Context c){ ns = new NotificationSettings(c, sbn.getPackageName()); extractStatusBarNotification(sbn, c); }
Example 17
Source File: NotificationListener.java From Mi-Band with GNU General Public License v2.0 | 4 votes |
private boolean shouldWeNotify(StatusBarNotification sbn) { String source = sbn.getPackageName(); Notification notification = sbn.getNotification(); if ((notification.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT) { return false; } /* do not display messages from "android" * This includes keyboard selection message, usb connection messages, etc * Hope it does not filter out too much, we will see... */ if (source.equals("android") || source.equals("com.android.systemui") || source.equals("com.android.dialer") || source.equals("com.android.mms") || source.equals("com.cyanogenmod.eleven") || source.equals("com.fsck.k9") || source.startsWith("com.motorola")) { return false; } App app = AppsSQLite.getInstance(NotificationListener.this).getApp(source); boolean passedTime = isAppInQueue(source); if(!passedTime) { if (lastNotificationMillis != -1) { if (Seconds.secondsBetween(new DateTime(lastNotificationMillis), new DateTime(System.currentTimeMillis())).getSeconds() < 5) { passedTime = false; } else { lastNotificationMillis = System.currentTimeMillis(); } } else { lastNotificationMillis = System.currentTimeMillis(); } } Log.i(TAG, "passedTime: " + passedTime); if (app != null) { Log.i(TAG, "app.shouldWeNotify(): " + app.shouldWeNotify()); } return !passedTime && app != null && app.shouldWeNotify(); }
Example 18
Source File: NotificationListener.java From MiPushFramework with GNU General Public License v3.0 | 4 votes |
private NotificationBarInfoItem buildItem(int i, StatusBarNotification statusBarNotification) { int i2 = 0; if (statusBarNotification == null || statusBarNotification.getPackageName() == null) { return null; } NotificationBarInfoItem notificationBarInfoItem = new NotificationBarInfoItem(); Notification notification = statusBarNotification.getNotification(); if (notification == null) { return null; } notificationBarInfoItem.setType(i); notificationBarInfoItem.setPackageName(statusBarNotification.getPackageName()); notificationBarInfoItem.setNotifyId(statusBarNotification.getId()); if (notification.extras != null) { notificationBarInfoItem.setTitle(notification.extras.getString("android.title", "")); notificationBarInfoItem.setContent(notification.extras.getString("android.text", "")); } notificationBarInfoItem.setCustomLayoutIsSet(notification.contentView != null); Object callMethod = JavaCalls.callMethod(notification.contentIntent, "getIntent", new Object[0]); if (callMethod != null && (callMethod instanceof Intent)) { notificationBarInfoItem.setIntentUri(((Intent) callMethod).toUri(1)); } notificationBarInfoItem.setArrivedTime(notification.when / 1000); notificationBarInfoItem.setRemovedTime(i == 2 ? System.currentTimeMillis() / 1000 : -1); notificationBarInfoItem.setFlags(notification.flags); notificationBarInfoItem.setPriority(notification.priority); if (notification.actions != null) { i2 = notification.actions.length; } notificationBarInfoItem.setActions(i2); notificationBarInfoItem.setDefaults(notification.defaults); if (VERSION.SDK_INT < 21) { return notificationBarInfoItem; } try { notificationBarInfoItem.setVisibility(((Integer) JavaCalls.getField(notification, "visibility")).intValue()); notificationBarInfoItem.setCategory((String) JavaCalls.getField(notification, "category")); notificationBarInfoItem.setColor(((Integer) JavaCalls.getField(notification, "color")).intValue()); return notificationBarInfoItem; } catch (Exception e) { return notificationBarInfoItem; } }
Example 19
Source File: Notification.java From an2linuxclient with GNU General Public License v3.0 | 4 votes |
public Notification(StatusBarNotification sbn, Context c){ ns = new NotificationSettings(c, sbn.getPackageName()); extractStatusBarNotification(sbn, c); }
Example 20
Source File: MutableStatusBarNotification.java From sdk with Apache License 2.0 | votes |
@RestrictTo(LIBRARY) static String getOpPkg(final StatusBarNotification sbn) { return sbn.getPackageName(); }