Example usage for android.service.notification StatusBarNotification getUser

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

Introduction

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

Prototype

public UserHandle getUser() 

Source Link

Document

The android.os.UserHandle for whom this notification is intended.

Usage

From source file:com.oasisfeng.android.service.notification.StatusBarNotificationCompat.java

@SuppressLint("NewApi") /** {@link StatusBarNotification#getUser()} is hidden but accessible in API level 18~20 */
public static UserHandle getUser(final StatusBarNotification sbn) {
    return sbn.getUser();
}

From source file:com.ademsha.appnotifico.NotificationDataHelper.java

public static JSONObject getStatusBarNotificationDataAsJSON(StatusBarNotification statusBarNotification) {
    JSONObject notification = new JSONObject();
    try {//ww w  . j a v  a  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;
}