3
我想使用這段代碼來檢測活動通知,我可以正確地獲取包名,但我也想獲取通知中的內容(真實消息)。我要發展我的應用程序讀取所有通知,包括短信等聊天應用程序,我的代碼如下:如何從StatusBar中的whatsapps通知中提取消息文本?
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getStringExtra("command").equals("clearall")){
NLService.this.cancelAllNotifications();
}
else if(intent.getStringExtra("command").equals("listwhats")){
Intent i1 = new Intent("WHATSAPP_LISTENER");
i1.putExtra("event","=====================");
sendBroadcast(i1);
int i=1;
for (StatusBarNotification sbn : NLService.this.getActiveNotifications()) {
if(sbn.getPackageName().equals("com.whatsapp")){
Intent i2 = new Intent("WHATSAPP_LISTENER");
i2.putExtra("event",i +" " + sbn.getPackageName() +" "+notificationText+sbn.getNotification().EXTRA_TITLE+" "
+sbn.getNotification().EXTRA_TEXT+ "\t" + sbn.getNotification().tickerText
+sbn.getNotification().contentIntent.toString() +sbn.toString() + "\n");
sendBroadcast(i2);
i++;
}
}
Intent i3 = new Intent("WHATSAPP_LISTENER");
i3.putExtra("event","===== Notification List ====");
sendBroadcast(i3);
}
}
}
提取通知是否有任何更多的細節或代碼例子 ? –