Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibrahimsn98/8fff106db18ba43baed96ea243b565fe to your computer and use it in GitHub Desktop.
Save ibrahimsn98/8fff106db18ba43baed96ea243b565fe to your computer and use it in GitHub Desktop.
Android notification listener get stacked notification text
String getNotificationText(Bundle extras) {
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();
CharSequence text = extras.getString("android.text");
if(!TextUtils.isEmpty(text))
return text.toString();
return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment