我正在尝试构建 Whatsapp 通知过滤应用程序,在其中监视来自 Whatsapp 的所有通知并根据过滤策略删除消息。
我可以使用下面的链接代码获取消息内容从 Parcelable、contentView 或 contentIntent 中提取通知文本 https://stackoverflow.com/questions/9292032/extract-notification-text-from-parcelable-contentview-or-contentintent仅适用于第一条消息
但问题是我只能获取第一条消息,如果用户没有阅读第一条消息,那么第二条消息之后我只能收到“来自发件人的两条消息”而不是实际的消息。
注意:我得到
android.text = 第一条消息的实际消息,但从第二条消息/通知开始为空
android.title = 发件人
android.summaryText = "n条新消息"
任何帮助,将不胜感激。
是的,最后经过几个小时的谷歌搜索后,我设计了一个对我有用的代码。
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 包含我想要的所有消息
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)