android - 如何从状态栏中的 whatsapp 通知中提取消息文本?

标签 android notifications

我正在尝试使用此代码来检测 Activity 通知,我可以正确获取包名称,但我还想获取通知中的内容(真实消息)。我想开发我的应用程序来读取所有通知,包括短信和其他聊天应用程序,我的代码如下:

 @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);

        }

    }

}

最佳答案

为了提取通知,您需要使用NotificationListnerService

关于android - 如何从状态栏中的 whatsapp 通知中提取消息文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27637231/

相关文章:

python - 关于在 sqlalchemy session 中刷新对象

android - pubnub.subscribe 没有响应

android - 如何设置安卓蓝牙权限

android - 如何找到哪些 android 设备属于 xdpi、mdpi、Idpi、xxhdpi、xhdpi

android - 状态更改时播放声音(Android)

android - AlarmManager 的更新时间 (Android)

Android - 增量状态栏通知图标

c# - Windows 10 通知 WPF

android - Firebase 应用中的图像邀请电子邮件 HTML 内容

android - 如何通过数据绑定(bind)使用 mvvm 模式