0

Im trying to create an app which includes chrome visited site logger function

here is my AccessibilityService

class CoreService : AccessibilityService(){

override fun onInterrupt() {
    return
}

var TAG  = "app:"

override fun onServiceConnected() { 
    Log.i(TAG,"Connected")
}

override fun onAccessibilityEvent(event: AccessibilityEvent) {
        Log.i(TAG,"onAccessibilityEvent")
        onChromeActivity(getRootInActiveWindow())
}

fun onChromeActivity(nodeInfo: AccessibilityNodeInfo) {

    var result = "|"
    var arra = nodeInfo.findAccessibilityNodeInfosByText("http");

    for (i in 0 until arra.size) {
        result += "\n" + arra.get(i).toString();
    }
    Log.i(TAG,"result: $result")
} 

}

xml config

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityFlags="flagDefault|flagIncludeNotImportantViews|flagRequestTouchExplorationMode|flagRequestEnhancedWebAccessibility|flagReportViewIds|flagRetrieveInteractiveWindows"
android:accessibilityEventTypes="typeWindowStateChanged"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="0"
android:canRetrieveWindowContent="true"
android:packageNames="com.android.chrome"
android:description="@string/desc"/>

So far im getting this logcat

2018-11-07 17:08:15.516 19631-19631/com.jmg21.omgi I/app:: result: | android.view.accessibility.AccessibilityNodeInfo@8000ccce; boundsInParent: Rect(0, 0 - 681, 131); boundsInScreen: Rect(115, 71 - 796, 202); packageName: com.android.chrome; className: android.widget.EditText; text: https://www.google.com; error: null; maxTextLength: -1; contentDescription: null; viewIdResName: com.android.chrome:id/url_bar; checkable: false; checked: false; focusable: true; focused: false; selected: false; clickable: true; longClickable: true; contextClickable: false; enabled: true; password: false; scrollable: false; actions: and so on...

The Problem is:

1. I only get this at one time if i try to go to other site nothing happen

2.I can not get the url

Please help and Thank you in advance!

Jayson Minard
  • 84,842
  • 38
  • 184
  • 227
Jakegarbo
  • 1,201
  • 10
  • 20

2 Answers2

0

The response to a similar question uses a depth-first search on the event itself, as opposed to getting the root of the active window.

I am using this code right now and it does successfully get the URL of each site visited. Though, if you want to parse the nodes faster (DFS on every event does consume significant time and resources), you can screen for specific events, such as "TYPE_VIEW_TEXT...", as this event triggers as the user types in the Chrome omnibox and you won't need to wait for the page to load.

Vivek B
  • 1
  • 2
0

Try adding the typeWindowContentChanged accessibility event type:

android:accessibilityEventTypes="typeWindowStateChanged|typeWindowContentChanged"
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287