Java Reflection getting message from WhatsApp by inner class on Android Notification -
i´m looking way messages whatsapp notifications when there more 1 line.
i´m trying value private variable inside inner class via reflection in android. i´m trying 'mtexts' arraylist of charsequence used build inboxstyle notification. i´m looking messages whatsapp since last whats update there no on notifications listened notificationlistener() have multiple lines notification (i can first line).
any way lines worth it.
this code.
@override public void onnotificationposted(statusbarnotification sbn) { super.onnotificationposted(sbn); class[] declaredclasses = sbn.getnotification().getclass().getclasses(); (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 mtext field correctly can´t value it.
i tried use new notification.inboxstyle() object
notification.inboxstyle istyleobjecttogetthevalue = new notification.inboxstyle();
to see if works well, , does
inboxstyle = (arraylist<charsequence>) fmtext.get(istyleobjecttogetthevalue);
but need values notification. idea on how can achieve that?
i tried message lines inflating remoteviews can retrieve statusbarnotification.getnotification().the_remote_view because using devicemonitor can take screenshoot of device , see ids of views... had no lucky that.
any way lines worth it.
all welcomed!! thanks!!
according docs remoteview.apply():
view apply(context context, viewgroup parent) - inflates view hierarchy represented object , applies of actions.
you can create parent , provide context remoteview.apply()
. inspect resulting view find text:
@nullable public view getbigcontentview (statusbarnotification statusbarnotification) { remoteviews bigcontentview = statusbarnotification.getnotification().bigcontentview; return bigcontentview != null ? bigcontentview.apply(ctx, null) : null; }
this might not work in nougat phones, according documentation (reading more tells me google did not mean read parameter , should used when building notification):
* of n, field may null. expanded notification view determined * inputs {@link notification.builder}; custom remoteviews can optionally * supplied {@link notification.builder#setcustombigcontentview(remoteviews)}.
Comments
Post a Comment