Example usage for android.widget RemoteViews getClass

List of usage examples for android.widget RemoteViews getClass

Introduction

In this page you can find the example usage for android.widget RemoteViews getClass.

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

@SuppressLint("UseSparseArrays")
public static ArrayList<String> extractor(Notification notification) {
    ArrayList<String> notifText = new ArrayList<String>();
    RemoteViews views = notification.contentView;
    @SuppressWarnings("rawtypes")
    Class secretClass = views.getClass();

    try {/* w ww .  j a v a 2  s.  co m*/

        Field outerFields[] = secretClass.getDeclaredFields();
        for (int i = 0; i < outerFields.length; i++) {

            if (!outerFields[i].getName().equals("mActions"))
                continue;

            outerFields[i].setAccessible(true);

            @SuppressWarnings("unchecked")
            ArrayList<Object> actions = (ArrayList<Object>) outerFields[i].get(views);
            for (Object action : actions) {

                Field innerFields[] = action.getClass().getDeclaredFields();

                Object value = null;
                Integer type = null;
                @SuppressWarnings("unused")
                Integer viewId = null;
                for (Field field : innerFields) {

                    field.setAccessible(true);
                    if (field.getName().equals("value")) {
                        value = field.get(action);
                    } else if (field.getName().equals("type")) {
                        type = field.getInt(action);
                    } else if (field.getName().equals("viewId")) {
                        viewId = field.getInt(action);
                    }
                }

                if (type != null && (type == 9 || type == 10) && value != null) {
                    // System.out.println("Type: " + Integer.toString(type)
                    // + " Value: " + value.toString());
                    if (!notifText.contains(value.toString()))
                        notifText.add(value.toString());
                }

            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return notifText;
}

From source file:com.harshad.linconnectclient.NotificationUtilities.java

@SuppressLint("DefaultLocale")
public static ArrayList<String> getNotificationText(Notification notification) {
    RemoteViews views = notification.contentView;
    Class<?> secretClass = views.getClass();

    try {//from w  w  w  . j av a2s  . c  o m
        ArrayList<String> notificationData = new ArrayList<String>();

        Field outerFields[] = secretClass.getDeclaredFields();
        for (int i = 0; i < outerFields.length; i++) {
            if (!outerFields[i].getName().equals("mActions"))
                continue;

            outerFields[i].setAccessible(true);

            @SuppressWarnings("unchecked")
            ArrayList<Object> actions = (ArrayList<Object>) outerFields[i].get(views);
            for (Object action : actions) {
                Field innerFields[] = action.getClass().getDeclaredFields();

                Object value = null;
                for (Field field : innerFields) {
                    field.setAccessible(true);
                    // Value field could possibly contain text
                    if (field.getName().equals("value")) {
                        value = field.get(action);
                    }
                }

                // Check if value is a String
                if (value != null && value.getClass().getName().toUpperCase().contains("STRING")) {

                    notificationData.add(value.toString());
                }
            }

            return notificationData;
        }
    } catch (Exception e) {
    }
    return null;
}

From source file:com.mattprecious.notisync.service.NotificationService.java

@SuppressLint("NewApi")
private CustomMessage getCustomMessage(PrimaryProfile profile, Notification notification, String packageName) {
    RemoteViews views = null;
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        views = notification.bigContentView;
    }// w ww  .java  2  s. c  o  m
    MyLog.d(TAG, "views: " + views);
    if (views == null) {
        views = notification.contentView;
    }
    if (views == null) {
        return null;
    }
    Class secretClass = views.getClass();
    ArrayList<String> listLong = new ArrayList<String>();
    ArrayList<String> listMessages = new ArrayList<String>();
    try {
        Map<Integer, String> text = new HashMap<Integer, String>();
        Field outerFields[] = secretClass.getDeclaredFields();

        for (int i = 0; i < outerFields.length; i++) {
            if (!outerFields[i].getName().equals("mActions"))
                continue;

            outerFields[i].setAccessible(true);

            ArrayList<Object> actions = (ArrayList<Object>) outerFields[i].get(views);
            for (Object action : actions) {
                Field innerFields[] = action.getClass().getDeclaredFields();

                Object value = null;
                Integer type = null;
                Integer viewId = null;
                for (Field field : innerFields) {
                    field.setAccessible(true);
                    if (field.getName().equals("value")) {
                        value = field.get(action);
                    } else if (field.getName().equals("type")) {
                        type = field.getInt(action);
                    } else if (field.getName().equals("viewId")) {
                        viewId = field.getInt(action);
                    }

                    if (type != null) {
                        if (type == 5) {
                            listLong.add(value.toString());
                        } else if (type == 9 || type == 10) {
                            listMessages.add(value.toString());
                        }
                    }
                }
            }
        }

        String testStrNumbers = "";
        for (int i = 0; i < listLong.size(); i++) {
            testStrNumbers += ", " + listLong.get(i);
        }
        String testStrMessages = "";
        for (int i = 0; i < listMessages.size(); i++) {
            testStrMessages += ", " + listMessages.get(i);
        }

        MyLog.d(TAG, "testStrNumbers: " + testStrNumbers);
        MyLog.d(TAG, "testStrMessages: " + testStrMessages);

    } catch (Exception e) {
        e.printStackTrace();
    }

    /*String bitmapString = bitmapToString(notification.largeIcon);
    Log.d("NotificationService", "BitmapString: " + bitmapString);
            
    Drawable icon = null;
    try {
       icon = getPackageManager().getApplicationIcon(profile.getPackageName());
    } catch (NameNotFoundException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }
    String iconString = drawableToString(icon);*/
    if (PACKAGE_WHATSAPP.equals(packageName)) {
        return new CustomMessage.Builder().tag(profile.getTag()).appName(profile.getName())
                .messageTitle(listMessages.get(0)).time(listLong.get(0)).message(listMessages.get(2))
                .packageName(profile.getPackageName())
                .tickerText((notification.tickerText != null) ? notification.tickerText.toString() : "")
                .unread("").account("").build();
    } else if (listMessages.size() >= 5) {
        return new CustomMessage.Builder().tag(profile.getTag()).appName(profile.getName())
                .messageTitle(listMessages.get(0)).time(listLong.get(0))
                .message(listMessages.get(3) + "\n" + listMessages.get(4)).packageName(profile.getPackageName())
                .tickerText((notification.tickerText != null) ? notification.tickerText.toString() : "")
                .unread(listMessages.get(1)).account(listMessages.get(2)).build();
    } else if (listMessages.size() == 4) {
        return new CustomMessage.Builder().tag(profile.getTag()).appName(profile.getName())
                .messageTitle(listMessages.get(0)).time(listLong.get(0)).message(listMessages.get(3))
                .packageName(profile.getPackageName())
                .tickerText((notification.tickerText != null) ? notification.tickerText.toString() : "")
                .unread(listMessages.get(1)).account(listMessages.get(2)).build();
    } else {
        return new CustomMessage.Builder().tag(profile.getTag()).appName(profile.getName())
                .messageTitle(listMessages.get(0)).time(listLong.get(0)).message(listMessages.get(1))
                .packageName(profile.getPackageName())
                .tickerText((notification.tickerText != null) ? notification.tickerText.toString() : "")
                .unread("").account("").build();
    }
}