Example usage for android.service.notification StatusBarNotification getPackageName

List of usage examples for android.service.notification StatusBarNotification getPackageName

Introduction

In this page you can find the example usage for android.service.notification StatusBarNotification getPackageName.

Prototype

public String getPackageName() 

Source Link

Document

The package of the app that posted the notification.

Usage

From source file:com.achep.acdisplay.notifications.NotificationUtils.java

public static Context createContext(Context context, StatusBarNotification n) {
    try {//from ww w  . ja  va 2s.  co m
        return context.createPackageContext(n.getPackageName(), Context.CONTEXT_RESTRICTED);
    } catch (PackageManager.NameNotFoundException e) {
        Log.w(TAG, "Failed to create notification\'s context");
        return null;
    }
}

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;//from   www  . jav  a 2 s  . c  o  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  w w . j  ava 2  s  .  c om*/
        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:org.durka.hallmonitor.NotificationService.java

@Override
public StatusBarNotification[] getActiveNotifications() {
    StatusBarNotification[] notifs = super.getActiveNotifications();

    List<StatusBarNotification> acc = new ArrayList<StatusBarNotification>(notifs.length);
    for (StatusBarNotification sbn : notifs) {
        Log.d(LOG_TAG + ".gAN", sbn.getPackageName());
        if (!blacklist.contains(sbn.getPackageName())) {
            acc.add(sbn);/*w ww .j  av a 2 s  . c o  m*/
        }
    }
    return acc.toArray(new StatusBarNotification[acc.size()]);
}

From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java

public void addToAlwaysArchived(StatusBarNotification sbn) {
    alwaysArchiveFilter.addPkgFilter(sbn.getPackageName());
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Set<String> set = sp.getStringSet(ALWAYS_ARCHIVE_PREF, null);
    if (set == null) {
        set = new HashSet<>();
    }/*from  w  ww  .j  a  v a 2 s.  c  om*/
    set.add(sbn.getPackageName());

    SharedPreferences.Editor editor = sp.edit();
    editor.putStringSet(ALWAYS_ARCHIVE_PREF, set);

    editor.apply();
}

From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java

public void removeFromAlwaysArchived(StatusBarNotification sbn) {
    alwaysArchiveFilter.removePkgFilter(sbn.getPackageName());
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Set<String> set = sp.getStringSet(ALWAYS_ARCHIVE_PREF, null);
    if (set == null) {
        return;//  w  ww.  j a  v  a  2 s  .  c  o m
    }
    set.remove(sbn.getPackageName());

    SharedPreferences.Editor editor = sp.edit();

    if (set.isEmpty())
        editor.remove(ALWAYS_ARCHIVE_PREF);
    else
        editor.putStringSet(ALWAYS_ARCHIVE_PREF, set);

    editor.apply();
}

From source file:com.yangtsaosoftware.pebblemessenger.services.NotificationService.java

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    if (sbn == null)
        return;/*from ww  w . ja  v  a 2s  .  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.");
    }
}

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());
}