Read content from notification parcelable objects for consequent notification

只愿长相守 提交于 2019-12-03 08:58:05

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");
        }

here JSONArray s contains all messages that I want

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!