title: Whatsapp Notification filtering app
body: <p>I am trying to build Whatsapp Notification filtering app, where I monitor all notification from Whatsapp and remove messages using some filter.
  so can some one help me how to catch those notification messages  so that I can manipulate them 
  I knew I have to use accessibility service but I am not able to get any event
  all that i get is null  source of event also null </p>
  
  <p><a href="https://stackoverflow.com/users/2452075/ghmulchandani">https://stackoverflow.com/users/2452075/ghmulchandani</a></p>
  
  <p>My codes are :- using accessibility service</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>package com.example.pavilion.accessebilityone;
  
  import android.content.Intent;
  
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.widget.EditText;
  import android.widget.TextView;
  
  public class MainActivity extends AppCompatActivity {
      static TextView tv;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          tv = (TextView)findViewById(R.id.textView);
          Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
          startActivityForResult(intent, 0);
  
          Intent service = new Intent(this,WhatsappService.class);
          startService(service);
      }
  }
  </code></pre>
  
  <p>Accessibility service class:-</p>
  
  <pre><code>import android.accessibilityservice.AccessibilityService;
  import android.accessibilityservice.AccessibilityServiceInfo;
  import android.app.Notification;
  import android.os.Parcelable;
  import android.util.Log;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.accessibility.AccessibilityEvent;
  import android.view.accessibility.AccessibilityNodeInfo;
  import android.view.accessibility.AccessibilityWindowInfo;
  import android.widget.RemoteViews;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.lang.reflect.Field;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  /**
   * Created by pavilion on 6/6/2017.
   */
  public class WhatsappService extends AccessibilityService {
  
      protected void onServiceConnected() {
          Toast.makeText(this, "connectd", Toast.LENGTH_SHORT).show();
          AccessibilityServiceInfo info = new AccessibilityServiceInfo();
          info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
          info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
          info.notificationTimeout = 100;
          setServiceInfo(info);
      }
  
      public synchronized void onAccessibilityEvent(AccessibilityEvent event) {
  
          if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
  
              CharSequence pk = event.getPackageName();
              //Toast.makeText(this,cl,Toast.LENGTH_SHORT).show();
              Toast.makeText(this, pk, Toast.LENGTH_SHORT).show();
              Notification n = (Notification) event.getParcelableData();
  
              if (n == null)
                  return;
  
              RemoteViews rv = n.contentView;
              View view = rv.apply(this, null);
  
              if (view == null)
                  return;
  
              if (view instanceof ViewGroup) {
                  ViewGroup group = (ViewGroup) view;
                  searchTextView(group);
              }
          }
      }
  
      @Override
      public void onInterrupt() {
      }
  
  
      private void searchTextView(ViewGroup group) {
          int count = group.getChildCount();
  
          for (int i = 0; i &lt; count; i++) {
              View v = group.getChildAt(i);
  
              if (v instanceof TextView) {
                 Toast.makeText(this,((TextView) v).getText(),Toast.LENGTH_SHORT).show();
              } else if (v instanceof ViewGroup) {
                  searchTextView((ViewGroup) v);
              }
          }
      }
  }
  </code></pre>
  
  <p>Manifest file:-</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.pavilion.accessebilityone"&gt;
      &lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/&gt;
      &lt;uses-permission android:name="android.permission.READ_SMS" /&gt;
      &lt;uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"/&gt;
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;service android:name=".WhatsappService"
  
              android:enabled="true"
              android:exported="true"
  
              android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
                  &lt;action android:name="android.accessibilityservice.AccessibilityService"/&gt;
              &lt;/intent-filter&gt;
              &lt;meta-data android:name="android.accessibilityservice"
                  android:resource="@xml/accessibilityservice"/&gt;
  
  
          &lt;/service&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>accessibility -service xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;accessibility-service
      android:accessibilityEventTypes="typeNotificationStateChanged"
  
  
      android:accessibilityFeedbackType="feedbackGeneric"
      android:canRetrieveWindowContent="true"
      android:notificationTimeout="100"
  
      android:settingsActivity="com.example.pavilion.accessebilityone.MainActivity"
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
  
  
  &lt;/accessibility-service&gt;
  </code></pre>