Android 如何从状态栏中的whatsapps通知中提取消息文本?
我试图使用此代码检测活动通知,我可以正确获取包名,但我还希望获取通知中的内容(真实消息)。我想开发我的应用程序来阅读所有通知,包括短信和其他聊天应用程序,我的代码如下:Android 如何从状态栏中的whatsapps通知中提取消息文本?,android,notifications,Android,Notifications,我试图使用此代码检测活动通知,我可以正确获取包名,但我还希望获取通知中的内容(真实消息)。我想开发我的应用程序来阅读所有通知,包括短信和其他聊天应用程序,我的代码如下: @Override public void onReceive(Context context, Intent intent) { if(intent.getStringExtra("command").equals("clearall")){ NLService.this.c
@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);
}
}
}
为了提取通知,您需要使用