Example usage for android.service.notification StatusBarNotification getClass

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

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

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