問題是如何在堆疊時(如在Whatsapp中)獲取所有傳入通知的TEXT(不是標題)字段。如何在Android中獲取堆疊通知的文本
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通知從單個用戶到達此行中的第一次(字符串文本= extras.getCharSequence( 「android.text」)的toString();)已成功讀取文本,但在此之後,當有更多消息進入並且通知堆積(如上圖所示)時,變量文本始終爲NULL。
這一定是可能的,因爲this app正在做它,測試它。它正在獲取每個應用程序的文本。
添加激勵:如果您知道答案或要嘗試的事情,還有另一個問題看起來類似問題here。
當第二個通知(比如來自A的例子)進入'sbn.getNotification()。extras。getCharSequence(Notification.EXTRA_TEXT)的ToString();」是NULL,那裏什麼也沒有。你是不是也看到它了?我正在嘗試Kitkat,API = 19 – user1406716 2015-03-31 09:00:54
我不確定這是否屬實,您是否可以詳細說明如何獲得以前的通知?:「*這種方式當新的發送者消息發出時,previoud通知也會出現,並且我們會得到回調在NotificationListener *「 – user1406716 2015-03-31 09:01:34
對於KitKat,它應該與AccessibilityService正常工作..嘗試使用此服務回調..在我的情況下,AccessibilityService正常工作,直到(<= KitKat),所以請檢查使用它 – Kushal 2015-03-31 09:07:46