Created
February 15, 2018 17:01
-
-
Save ibrahimsn98/8fff106db18ba43baed96ea243b565fe to your computer and use it in GitHub Desktop.
Android notification listener get stacked notification text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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