Example usage for android.service.notification StatusBarNotification getPostTime

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

Introduction

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

Prototype

public long getPostTime() 

Source Link

Document

The time (in System#currentTimeMillis time) the notification was posted, which may be different than android.app.Notification#when .

Usage

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:com.ademsha.appnotifico.NotificationDataHelper.java

public static JSONObject getStatusBarNotificationDataAsJSON(StatusBarNotification statusBarNotification) {
    JSONObject notification = new JSONObject();
    try {//from w ww . j  av a2  s .  c  o  m
        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.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;// w  w  w .  ja v a  2 s.  c  o  m
    }

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