我正在尝试构建Whatsapp通知过滤应用程序,在那里我监控来自Whatsapp的所有通知,并根据过滤策略删除消息。
对于第一条消息,我可以使用下面的链接代码Extract notification text from parcelable, contentView or contentIntent获取消息内容。
但问题是,我只能获取第一条消息,如果用户不读取第一条消息,那么第二条消息之后,我只能从发送方获得"2条消息“,而不是实际消息。
注:我得到了
android.text =第一条消息的实际消息,但从第二条消息/通知开始,它的空值为android.title =发送方android.summaryText = "n条新消息“
任何帮助都将不胜感激。
发布于 2015-03-09 14:28:21
是的,最后,经过几个小时的googling搜索,我设计了一个对我有用的代码。
Bundle extras = sbn.getNotification().extras;
CharSequence[] lines = extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES);
JSONArray s = new JSONArray();
for (CharSequence msg : lines) {
msg = removeSpaces(msg);
if (!TextUtils.isEmpty(msg)) {
s.put(msg.toString());
}
}
private static String removeSpaces(@Nullable CharSequence cs) {
if (cs == null)
return null;
String string = cs instanceof String ? (String) cs : cs.toString();
return string.replaceAll("(\\s+$|^\\s+)", "").replaceAll("\n+", "\n");
}这里,JSONArray s包含我想要的所有消息。
https://stackoverflow.com/questions/27745342
复制相似问题