问题描述
我想建立WhatsApp的通知过滤的应用程序,我在那里监视WhatsApp的所有通知和删除邮件按过滤策略。
I am trying to build Whatsapp Notification filtering app, where I monitor all notification from Whatsapp and remove messages as per filtering policy.
我可以使用下面的链接code获取的信息内容Extract从parcelable,内容查看或contentIntent 的第一条消息通知文本仅
I can fetch message content using below link codeExtract notification text from parcelable, contentView or contentIntent for first message only
但问题是,我可以只读取第一个消息,如果用户不看第一条消息,然后第二个消息开始我只得到2的消息从发送者,而不是实际的消息。
but the problem is I can fetch only first message, if user does not read first message then second message onwards I get only "2 messages from sender" instead of actual message.
注:我收到
android.text =实际的消息,但是从第二个消息/通知起的空android.title =发件人android.summaryText =N新邮件
android.text = actual message for first message but its null from second message/notification onwardsandroid.title = senderandroid.summaryText = "n new messages"
任何帮助将是AP preciated。
any help would be appreciated.
推荐答案
是的,最后几个小时的谷歌搜索我设计了一个code这确实为我工作后。
Yes, finally after few hours of googling I design a code which does work for me.
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包含的所有消息,我想
here JSONArray s contains all messages that I want
这篇关于阅读从通知parcelable对象为随之而来的通知内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!