Example usage for android.service.notification StatusBarNotification getId

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

Introduction

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

Prototype

public int getId() 

Source Link

Document

The id supplied to android.app.NotificationManager#notify(int,Notification) .

Usage

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   ww  w  .jav a2s. com*/
@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.cyanogenmod.messaging.quickmessage.QuickMessagePopup.java

/**
 * Clears the status bar notification and, optionally, mark all messages as read
 * This is used to clean up when we are done with all qm's
 *
 * @param markAsRead - should remaining qm's be maked as read?
 *///from   w w  w. j av  a2  s  .  c o m
private void clearNotification(boolean markAsRead) {
    // Dismiss the notification that brought us here.
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    StatusBarNotification[] statusBarNotifications = notificationManager.getActiveNotifications();
    final String packageName = getPackageName();
    for (StatusBarNotification statusBarNotification : statusBarNotifications) {
        if (packageName.equals(statusBarNotification.getPackageName())) {
            notificationManager.cancel(statusBarNotification.getTag(), statusBarNotification.getId());
            break;
        }
    }

    // Mark all contained conversations as seen
    if (markAsRead) {
        markAllMessagesRead();
    }

    // Clear the messages list
    mMessageList.clear();

    if (DEBUG)
        Log.d(LOG_TAG, "clearNotification(): Message list cleared. Size = " + mMessageList.size());
}

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

/**
 * Note, that method is not equals with {@link #equals(Object)} method.
 *
 * @param n notification to compare with.
 * @return {@code true} if notifications are from the same source and will
 * be handled by system as same notifications, {@code false} otherwise.
 *///w ww  . j a  v  a 2  s  .  c  om
@SuppressLint("NewApi")
@SuppressWarnings("ConstantConditions")
public boolean hasIdenticalIds(@Nullable OpenNotification n) {
    if (n == null)
        return false;
    StatusBarNotification sbn = getStatusBarNotification();
    StatusBarNotification sbn2 = n.getStatusBarNotification();
    if (Device.hasLemonCakeApi()) {
        // FIXME: Android L reflections.
        // service.cancelNotification(notification.getKey());
        try {
            Method method = sbn.getClass().getMethod("getKey");
            method.setAccessible(true);
            String key = (String) method.invoke(sbn);
            String key2 = (String) method.invoke(sbn2);

            return new EqualsBuilder().append(key, key2).isEquals();
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
            /* sad, but true */ }
    }
    return new EqualsBuilder().append(sbn.getId(), sbn2.getId()).append(getPackageName(), n.getPackageName())
            .append(sbn.getTag(), sbn2.getTag()).isEquals();
}

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;/*from w  w  w. j  a 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);
}