Example usage for android.service.notification StatusBarNotification getKey

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

Introduction

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

Prototype

public String getKey() 

Source Link

Document

A unique instance key for this notification record.

Usage

From source file:org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationsPlugin.java

public static String getNotificationKeyCompat(StatusBarNotification statusBarNotification) {
    String result;//from  w  ww.j a v  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.achep.acdisplay.notifications.OpenNotificationKitKatWatch.java

/**
 * {@inheritDoc}//from   w ww. j  av a2s  .c  om
 */
@Override
public boolean hasIdenticalIds(@Nullable OpenNotification n) {
    if (n == null)
        return false;
    StatusBarNotification sbn = getStatusBarNotification();
    StatusBarNotification sbn2 = n.getStatusBarNotification();
    assert sbn2 != null;
    return new EqualsBuilder().append(sbn2.getKey(), sbn.getKey()).isEquals();
}

From source file:com.android.example.notificationlistener.NotificationListenerActivity.java

public void dismiss(View v) {
    Log.d(TAG, "clicked dismiss ");
    Object tag = v.getTag();/*from   w w  w .  jav  a  2 s. c  om*/
    if (tag instanceof StatusBarNotification) {
        StatusBarNotification sbn = (StatusBarNotification) tag;
        Log.d(TAG, "  on " + sbn.getKey());
        LocalBroadcastManager.getInstance(this)
                .sendBroadcast(new Intent(Listener.ACTION_DISMISS).putExtra(Listener.EXTRA_KEY, sbn.getKey()));
    }
}

From source file:com.android.example.notificationlistener.NotificationListenerActivity.java

public void launch(View v) {
    Log.d(TAG, "clicked launch");
    Object tag = v.getTag();/*from   w  w  w  .ja  va2s.  c o m*/
    if (tag instanceof StatusBarNotification) {
        StatusBarNotification sbn = (StatusBarNotification) tag;
        Log.d(TAG, "  on " + sbn.getKey());
        LocalBroadcastManager.getInstance(this)
                .sendBroadcast(new Intent(Listener.ACTION_LAUNCH).putExtra(Listener.EXTRA_KEY, sbn.getKey()));
    }
}

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 w w .  j  a  va  2  s.  co  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());
}

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

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