Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Field;
import java.util.ArrayList;
import android.annotation.SuppressLint;

import android.app.Notification;

import android.widget.RemoteViews;

public class Main {
    @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 {

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