I am trying to extract some data from an android notification. When I receive a mail, I can get the name of the sender from the title attribute and the rest of the notification is in the text attribute with the following code:
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
if (sbn.getPackageName().equals("com.google.android.gm") {
String title = sbn.getNotification().extras.getString(Notification.EXTRA_TITLE);
String text = "";
text = sbn.getNotification().extras.getCharSequence(Notification.EXTRA_TEXT).toString();
Log.i(TAG, "Title: " + title);
Log.i(TAG, "Text: " + text);
}
Given now the following screenshot of a notification. Android mail notification
The title is no longer the name of the sender (but 6 new messages) so I thought to take the text below and extract the name, but my code from above doesn't work because of an NullPointerException in line of text = sbn.getNotification()...
What am I missing or doing wrong? Does anyone know how to get the whole text or even a nice method to get the senders name?
Cheers