Situation:
I have code that is reading the text of a notification
String notificationText = sbn.getNotification().extras.getString("android.text");
and it causes the following error when a notification with special characters is read:
Key android.text expected String but value was a android.text.SpannableString.
The default value <null> was returned.
java.lang.ClassCastException: android.text.SpannableString cannot be cast to java.lang.String
The particular text that caused this error was a notification from com.whatsapp with the text: "bold text regular text"
Note that some characters are in bold. (no exception is thrown without the bold).
Question:
Is there a way for me to get this text as a string?
I have already unsuccessfully tried:
In my case struggled almost 3 hrs
String.valueOf(sbn.getNotification().extras.get("android.text"));
worked like a charm