Home » Android » android – Listen to incoming Whatsapp messages/notifications

android – Listen to incoming Whatsapp messages/notifications

Posted by: admin April 23, 2020 Leave a comment


I’m working on a notification based app, for which I need to listen to incoming notifications. I’ve been able to listen to incoming calls, SMS, mail etc. I have no clue how to listen for pings or messages from friends on Whatsapp via code. Can this actually be done? If so, how? Can Accessibility Service be used for this, using Package Name as “com.whatsapp”?

How to&Answers:

I was able to do this using Accessibility Service . Using this, you can listen to all notification on the notification bar. I listened to application-specification by adding the package name to the Accessibility Service service info , which in this case was com.whatsapp. I couldn’t read the messages, but I get notified whenever a message arrives.



You can actually parse incoming notifications and the messages within since Android 4.2. I’ve done this: https://github.com/Snirpo/whatsapprelay. This is done with an accessibilityservice. Currently it parses messages from a certain WhatsApp group. But it can be adapted to parse all messages. Sending messages trough WhatsApp is more difficult unfortunatly.


Unless Developers of that app intentionally share a service , a content provider, or intentionally send out public broadcasts of events, or expose a custom broadcast registering system, there is no legitimate way in android to listen to internal workings of a third party App. App isolation is designed in Android for a very important reason: security.


Accessibility events only catch incoming notifications event, not when they are updated. For now, WhatsApp notifications don’t display the message, only the sender. The message is then added by the WhatsApp app with an update, which can’t be caught by the accessibility service.

You will only have something like “1 new message from XXX”, but that may be sufficient to your needs.


See below example to catch whatsapp notifications:

public class Notifier extends AccessibilityService {

public void onCreate(){
    //Toast.makeText(this,"Oncreate", Toast.LENGTH_LONG).show();


protected void onServiceConnected() {
    // Set the type of events that this service wants to listen to.  Others
    // won't be passed to this service.
    Toast.makeText(this,"Service connected", Toast.LENGTH_LONG).show();
    AccessibilityServiceInfo info = new AccessibilityServiceInfo();
    info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;;
    info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED ;

    // If you only want this service to work with specific applications, set their
    // package names here.  Otherwise, when the service is activated, it will listen
    // to events from all applications.
    info.packageNames = new String[] {"com.whatsapp"};
    info.notificationTimeout = 100;



public void onAccessibilityEvent(AccessibilityEvent event) {

    if(event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {

            Toast.makeText(this,"Notification Catched", Toast.LENGTH_LONG).show();


And don’t forget to set permission from settings>Accessibility in order to access the system events. Allow permission from settings .

check this link

accessibility service is not started


I listened to incoming WhatsApp message notifications with the help of this 2 parted article which you can read it from here.

  1. Configure AndroidManifest.xml
<!-- AndroidManifest.xml -->
    android:label="My application"
        <action android:name="android.accessibilityservice.AccessibilityService" />

        android:resource="@xml/serviceconfig" />
  1. Create a new file called serviceconfig.xml in /xml/ directory.
<!-- serviceconfig.xml -->
    android:canRequestTouchExplorationMode="true"  />
  1. Create a new MyAccessibilityService class which extends AccessibilityService.
protected void onServiceConnected() {
        AccessibilityServiceInfo info = new AccessibilityServiceInfo();
        info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
        info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
        info.notificationTimeout = 100;
        info.packageNames = null;

public void onAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
        if (event.getPackageName().toString().equals("com.whatsapp")){
            StringBuilder message = new StringBuilder();
            if (!event.getText().isEmpty()) {
                for (CharSequence subText : event.getText()) {

                // Message from +12345678

  1. It’s ready. Now you can customize the service for your needs.

Note: Because accessibility services are able to explore and interact with on-screen content, a user has to explicitly enable services in Settings > Accessibility. More details


To send replies to received notifications check out this answer.