Вопрос в том, как получить поле ТЕКСТ (не заголовок) всех входящих уведомлений, когда они складываются (как в 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);
}
} В первый раз, когда приходит уведомление Whatsapp от одного пользователя, эта строка (String text = extras.getCharSequence("android.text").toString();) может быть успешно прочитана text, но после этого, когда приходит больше сообщений и уведомления накапливаются (как на картинке выше), переменная text всегда равна NULL.
Это должно быть возможно, поскольку это приложение выполняет это, протестировал. Он получает текст каждого приложения.
Добавленное поощрение: если вы знаете ответ или что можно попробовать, есть еще один вопрос, похожий на вопрос здесь.