I hope this doesn't violate any rule as I've tried following the How-to-ask guide.
I'm trying to read incoming notifications using NotificationListenerService and it works for me but only partially.
The first notification of it's type, lets say - whatsapp I can get the ticker, text and title but then if the notifications stack up I no longer can read the text of the messages.
How do I get the text of stacked up notifications?
Here is the code I currently implement:
public class NotificationService extends NotificationListenerService {
private Context context;
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
String pack = sbn.getPackageName();
String ticker = sbn.getNotification().tickerText.toString();
Bundle extras = sbn.getNotification().extras;
String title = "";
String text = "";
if (extras.containsKey("android.title")) {
title = extras.getString("android.title");
}
if (extras.containsKey("android.text")) {
if (extras.getCharSequence("android.text") != null) {
text = extras.getCharSequence("android.text").toString();
}
}
if (pack != null) {
Log.i("Package", pack);
}
if (ticker != null) {
Log.i("ticker", ticker);
}
if (title != null) {
Log.i("Title", title);
}
if (text != null) {
Log.i("Text", text);
}
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
}
}
https://developer.android.com/reference/android/service/notification/NotificationListenerService.html Sorry, but i don't find any way to get updates on notifications – Sulfkain Apr 07 '15 at 14:45