Java反射从Android上的内部类获取WhatsApp的消息通知
我正在寻找一种方法来从WhatsApp通知中获取消息,当有多行时。Java反射从Android上的内部类获取WhatsApp的消息通知
我想通过Android中的Reflection从内部类中的私有变量中获取值。我正尝试获取用于构建InboxStyle通知的charsequence的'mTexts'ArrayList。我正在寻找whatsapp自最后一次更新之后的消息,其中没有EXTRA on notification by listeListener(),它具有多行通知(我只能得到第一行)。
任何获得线条的方法都是值得的。
这是我的代码。
@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());
}
}
}
}
}
}
我正确地到达多行文字场,但我不能得到它的价值。
我试图用一个新的Notification.InboxStyle()对象
Notification.InboxStyle iStyleObjectToGetTheValue = new Notification.InboxStyle();
,看它是否运作良好,它也
inboxStyle = (ArrayList<CharSequence>) fmText.get(iStyleObjectToGetTheValue);
,但我需要从通知的值。任何想法,我怎么能实现这一点?
我也试图得到消息系充气RemoteViews,您可以通过StatusBarNotification.getNotification()检索。THE_REMOTE_VIEW因为使用设备监视器您可以对设备的screenshoot看到的的ID意见......但没有幸运的。
任何获得线条的方法都是值得的。
所有的帮助是欢迎的! 谢谢!
按照文档的RemoteView.apply():
查看应用(上下文的背景下,一个ViewGroup父) - 膨胀该对象表示视图层级和所有适用的行动。
您可以创建一个父级并向RemoteView.apply()
提供上下文。检查结果视图查找的文字:
@Nullable
public View getBigContentView (StatusBarNotification statusBarNotification) {
RemoteViews bigContentView = statusBarNotification.getNotification().bigContentView;
return bigContentView != null ? bigContentView.apply(ctx, null) : null;
}
这可能不是在牛轧糖手机上运行,如根据文件(阅读更细致地告诉我,谷歌可能并不意味着你阅读此参数和
* As of N, this field may be null. The expanded notification view is determined by the * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}.
当试图膨胀bigContentView()时,我得到空指针。这是我的代码... RemoteViews rv = sbn.getNotification()。bigContentView; LayoutInflater inflater =(LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); ViewGroup localView =(ViewGroup)inflater.inflate(rv.getLayoutId(),null); rv.reapply(ctx.getApplicationContext(),localView);对于(int i = 0; i Dan
没有幸运的是...没有任何东西可以使用...只有2个ID没有兴趣。我怎么知道这个ID是否属于这个ID? – Dan
你能不能从通知获取内容查看/ bigContentView并检查他们找到文本:建立通知)时,才应使用? –
如何检查远程视图? - 我试图通过获取视图节点进行搜索,但没有发现任何可靠的...也许我做错了... – Dan