title: Can AccessibilityService perform click event on Background App without opening the app
body: <p>From my MainActivity I'm using AccessibilityService to perform click event on another app and it works when I open the app and it is displayed on the screen. However I want to perform the click event without having to open the app, it can be opened but not currently displayed on the screen.</p>
  
  <p>Is this possible?</p>
  
  <pre><code>public class DiaryAppAccessibilityService extends AccessibilityService {
  
  
  @Override
  protected void onServiceConnected() {
      super.onServiceConnected();
  }
  
  @Override
  public void onAccessibilityEvent (AccessibilityEvent event) {
  
  
      if (getRootInActiveWindow () == null) {
          return;
      }
  
      AccessibilityNodeInfoCompat rootInActiveWindow = AccessibilityNodeInfoCompat.wrap (getRootInActiveWindow());
  
      List&lt;AccessibilityNodeInfoCompat&gt; messageNodeList = rootInActiveWindow.findAccessibilityNodeInfosByViewId ("com.diaryapp:id/entry");
      if (messageNodeList == null || messageNodeList.isEmpty ()) {
          return;
      }
  
      AccessibilityNodeInfoCompat messageField = messageNodeList.get (0);
  
      if (messageField.getText () == null || messageField.getText ().length () == 0
              || !messageField.getText ().toString ().endsWith (getApplicationContext ().getString (R.string.diaryapp_suffix))) { // So your service doesn't process any message, but the ones ending your apps suffix
          return;
      }
  
      List&lt;AccessibilityNodeInfoCompat&gt; sendMessageNodeInfoList = rootInActiveWindow.findAccessibilityNodeInfosByViewId ("com.diaryapp:id/send");
      if (sendMessageNodeInfoList == null || sendMessageNodeInfoList.isEmpty ()) {
          return;
      }
  
      AccessibilityNodeInfoCompat sendMessageButton = sendMessageNodeInfoList.get (0);
  
  
      // Now fire a click on the send button
      sendMessageButton.performAction (AccessibilityNodeInfo.ACTION_CLICK);
  
      @Override
      public void onInterrupt() {
  
      }
  }
  </code></pre>
  
  <p>XML config</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;accessibility-service
  xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes="typeWindowContentChanged"
    android:accessibilityFeedbackType="feedbackSpoken"
    android:accessibilityFlags="flagDefault"
    android:notificationTimeout="100"
    android:canRetrieveWindowContent="true"
  &lt;/accessibility-service&gt;
  </code></pre>
  
  <p>I removed this</p>
  
  <pre><code>android:packageNames="com.diaryapp"
  </code></pre>
  
  <p>because I want the service to be active in other apps and be able to perform the click event from there.</p>