How to extract message text from whatsapps notification in StatusBar?

I am trying to use this code to detect active notifications, I can get the package name correctly, but I want to get the content (real message) in the notifications as well. I want to develop an app to read all notifications including SMS and other chat apps, my code is below:

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

        }

    }

}

      

+3


source to share


1 answer


To retrieve notifications you need to use NotificationListnerService



0


source







All Articles