Java Code Examples for android.service.notification.StatusBarNotification#getKey()

The following examples show how to use android.service.notification.StatusBarNotification#getKey() . 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: NotificationObject.java    From android-notification-log with MIT License 5 votes vote down vote up
NotificationObject(Context context, StatusBarNotification sbn, final boolean LOG_TEXT, int reason) {
	this.context = context;
	this.LOG_TEXT = LOG_TEXT;

	n           = sbn.getNotification();
	packageName = sbn.getPackageName();
	postTime    = sbn.getPostTime();
	systemTime  = System.currentTimeMillis();

	isClearable = sbn.isClearable();
	isOngoing   = sbn.isOngoing();

	nid         = sbn.getId();
	tag         = sbn.getTag();

	if(Build.VERSION.SDK_INT >= 20) {
		key     = sbn.getKey();
		sortKey = n.getSortKey();
	}

	removeReason = reason;

	extract();

	if(Const.ENABLE_ACTIVITY_RECOGNITION || Const.ENABLE_LOCATION_SERVICE) {
		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
		lastActivity = sp.getString(Const.PREF_LAST_ACTIVITY, null);
		lastLocation = sp.getString(Const.PREF_LAST_LOCATION, null);
	}
}
 
Example 2
Source File: MutableStatusBarNotification.java    From sdk with Apache License 2.0 5 votes vote down vote up
private void updateKey() {
	if (! Objects.equals(mTag, super.getTag()) || mId != super.getId()) {		// Initial PID and score has no contribution to generated key.
		final StatusBarNotification sbn = new StatusBarNotification(getPackageName(), null, getId(), getTag(),
				getUid(this), 0, 0, super.getNotification(), getUser(), getPostTime());
		if (SDK_INT >= N) sbn.setOverrideGroupKey(getOverrideGroupKey());
		mKey = sbn.getKey();
	} else mKey = null;
}
 
Example 3
Source File: NotificationListenerService.java    From heads-up with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onNotificationPosted(StatusBarNotification statusBarNotification) {
    try {
        /* if Show non-cancellable notifications is selected then need not check
        for Ongoing / Clearable as there will be ongoing notification by the background
         service which is trying to display.
        if Show non-cancellable notifications is not selected then existing logic
        prevails
         */
        if ((statusBarNotification.isOngoing() || !statusBarNotification.isClearable())
            && !PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).
                getBoolean("show_non_cancelable", false)) return;

        if (NotificationListenerAccessibilityService.doLoadSettings) doLoadSettings();

        String statusBarNotificationKey = null;
        if (Build.VERSION.SDK_INT >= 20) statusBarNotificationKey = statusBarNotification.getKey();

        DecisionMaker decisionMaker = new DecisionMaker();

        decisionMaker.handleActionAdd(statusBarNotification.getNotification(),
                statusBarNotification.getPackageName(),
                statusBarNotification.getTag(),
                statusBarNotification.getId(),
                statusBarNotificationKey,
                getApplicationContext(),
                "listener");
    } catch (NullPointerException e) {
        e.printStackTrace();
        Mlog.e(logTag, "NPE");
    }
}
 
Example 4
Source File: NotificationKeyData.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
public static NotificationKeyData fromNotification(StatusBarNotification sbn) {
    Notification notif = sbn.getNotification();
    return new NotificationKeyData(sbn.getKey(), AndroidVersion.isAtLeastOreo() ? notif.getShortcutId() : null, notif.number);
}
 
Example 5
Source File: StatusService.java    From Status with Apache License 2.0 4 votes vote down vote up
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());
}