vendredi 7 avril 2017

Java Reflection getting message from WhatsApp by inner class on Android Notification

I´m looking for a way to get the messages from WhatsApp notifications when there is more than one line.

I´m trying to get the value from a private variable inside an inner class via Reflection in Android. I´m trying to get the 'mTexts' ArrayList of charsequence used to build an InboxStyle Notification. I´m looking for the messages from whatsapp since the last whats update there is no EXTRA on Notifications listened by notificationListener() that have the multiple lines notification (I can only get the first line).

Any way to get the lines is worth it.

This is my code.

@Override
    public void onNotificationPosted(StatusBarNotification sbn) {
        super.onNotificationPosted(sbn);

     Class[] declaredClasses = sbn.getNotification().getClass().getClasses();

        for (Class c : declaredClasses){

            if(c.getName().contains("Notification$InboxStyle")){
                Class inboxStyleClass = c.getClass();

                Field[] fields = inboxStyleClass.getDeclaredFields();

                for(Field field : fields){

                    if(field.getName().contains("mText")){

                        Field fmText = null;
                        try {
                            fmText = inboxStyleClass.getDeclaredField("mTexts");
                        } catch (NoSuchFieldException e) {
                            e.printStackTrace();
                        }

                        ArrayList<CharSequence> mTextsArrayList = null;

                        fmText.setAccessible(true);

                        try{
                            mTextsArrayList = (ArrayList<CharSequence>) fmText.get(**WICH OBJECT MAY USE HERE**);
                        }catch(IllegalAccessException e){
                            e.printStackTrace();
                        }

                        for(CharSequence value : mTextsArrayList){
                            Log.i("XXX","Results are: "+value.toString());
                        }
                    }
                }

            }

        }

}

I reach the mText field correctly but I can´t get the value from it.

I tried to use a new Notification.InboxStyle() object

 Notification.InboxStyle iStyleObjectToGetTheValue = new Notification.InboxStyle();

to see if it works well, and it does

inboxStyle = (ArrayList<CharSequence>) fmText.get(iStyleObjectToGetTheValue);

but I need the values from the notification. Any idea on how can I achieve that?

I also tried to get the message lines inflating the RemoteViews that you can retrieve by StatusBarNotification.getNotification().THE_REMOTE_VIEW because using DeviceMonitor you can take an screenshoot of the device and see the IDs of the views... but had no lucky with that.

Any way to get the lines is worth it.

All the help is welcomed!! Thanks!!





Aucun commentaire:

Enregistrer un commentaire