How to get text of Stacked Notifications in Android

后端 未结 4 1357
囚心锁ツ
囚心锁ツ 2020-12-15 23:53

The question is how to get the TEXT (not title) field of all incoming notifications when they get stacked (like in Whatsapp).

4条回答
  •  独厮守ぢ
    2020-12-16 00:17

    I think this can help you:

    CharSequence[] lines = 
    extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES);
    if(lines != null && lines.length > 0) {
       StringBuilder sb = new StringBuilder();
       for (CharSequence msg : lines)
          if (!TextUtils.isEmpty(msg)) {
             sb.append(msg.toString());
             sb.append('\n');
          }
       return sb.toString().trim();
    }
    CharSequence chars = 
    extras.getCharSequence(Notification.EXTRA_BIG_TEXT);
    if(!TextUtils.isEmpty(chars))
       return chars.toString();
    

提交回复
热议问题