title: Android : Read Google chrome URL using accessibility service
body: <p>I want to read the url user has entered in his browser. Here is my accessibility service code.</p>
  
  <pre><code>&lt;accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
  android:accessibilityFlags="flagDefault"
  android:accessibilityEventTypes="typeWindowStateChanged"
  android:accessibilityFeedbackType="feedbackGeneric"
  android:notificationTimeout="0"
  android:canRetrieveWindowContent="true"
  android:packageNames="com.android.chrome"
  android:description="@string/accessibility_description"
  /&gt;
  </code></pre>
  
  <p>In AndroidManifest</p>
  
  <pre><code>&lt;service android:name=".MyAccessibilityService"
          android:label="@string/accessibility_title"
          android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.accessibilityservice.AccessibilityService"/&gt;
          &lt;/intent-filter&gt;
          &lt;meta-data
              android:name="android.accessibilityservice"
              android:resource="@xml/accessibility_service_config" /&gt;
      &lt;/service&gt;
  </code></pre>
  
  <p>In MyAccessibilityService</p>
  
  <pre><code> public void onAccessibilityEvent(AccessibilityEvent event) {
      debug("On accessibility event");
      getChromeUrl(getRootInActiveWindow());
  }
  
  public void getChromeUrl(AccessibilityNodeInfo nodeInfo) {
      //Use the node info tree to identify the proper content.
      //For now we'll just log it to logcat.
      Log.d(TAG, toStringHierarchy(nodeInfo, 0));
  }
  private String toStringHierarchy(AccessibilityNodeInfo info, int depth) {
      if (info == null) return "";
  
      String result = "|";
      for (int i = 0; i &lt; depth; i++) {
          if (result.contains("http")) {
              Log.d(TAG, "Found URL!!!!!!!!!!!!!!" + result);
          }
          result += "  ";
      }
  
      result += info.toString();
  
      for (int i = 0; i &lt; info.getChildCount(); i++) {
          result += "\n" + toStringHierarchy(info.getChild(i), depth + 1);
      }
  
      return result;
  }
  private static void debug(Object object) {
      Log.d(TAG, object.toString());
  }
  </code></pre>
  
  <p>Problem is i am getting views from content in the url in my rootview, not the top address bar. Any help is appreciated. </p>