The question is how to get the TEXT (not title) field of all incoming notifications when they get stacked (like in Whatsapp).
public class NLService extends NotificationListenerService {
public void onNotificationPosted(StatusBarNotification sbn) {
Log.v(Constants.TAG_notifs,
"------------------------- in onNotificationPosted(), Notification Text = "
+ sbn.getNotification().tickerText);
Bundle extras = sbn.getNotification().extras;
if (extras.containsKey("android.text")) {
if (extras.getCharSequence("android.text") != null) {
String text = extras.getCharSequence("android.text").toString();
Log.v(Constants.TAG_notifs,
"------------------------- in onNotificationPosted(), Bundle.text != NULL, so here it is = "
+ text);
}
}
if (extras.containsKey("android.title")) {
Log.v(Constants.TAG_notifs,
"------------------------- in onNotificationPosted(), Bundle android.title = "
+ extras.getString("android.title"));
}
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
//super.onNotificationRemoved(sbn);
}
} The first time when a Whatsapp notification arrives from a single user this line (String text = extras.getCharSequence("android.text").toString();) is successfully able to read text, but after that when more messages come in and notifications get stacked (like in the picture shown above), the variable text is always NULL.
This must be possible because this app is doing it, tested it. It is getting the text of each and every app.
Added Incentive: If you know the answer or things to try, there is another question which looks similar question here.