9
9
import android .content .Intent ;
10
10
import android .util .Log ;
11
11
import android .view .accessibility .AccessibilityEvent ;
12
+ import android .view .accessibility .AccessibilityNodeInfo ;
12
13
13
14
public class MyAccessibilityService extends AccessibilityService {
14
15
@@ -30,31 +31,42 @@ public void onServiceConnected() {
30
31
// Set the type of events that this service wants to listen to. Others won't be passed to this service.
31
32
// We are only considering windows state changed event.
32
33
AccessibilityServiceInfo info = new AccessibilityServiceInfo ();
33
- info .eventTypes = AccessibilityEvent .TYPE_WINDOWS_CHANGED | AccessibilityEvent .TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent .TYPE_WINDOW_CONTENT_CHANGED ;
34
+ info .eventTypes = AccessibilityEvent .TYPE_WINDOWS_CHANGED | AccessibilityEvent .TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent .TYPE_WINDOW_CONTENT_CHANGED ;
34
35
// 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.
35
- // info.packageNames = new String[]{"com.example.android.myFirstApp", "com.example.android.mySecondApp" };
36
+ info .packageNames = new String []{"com.contextlogic.wish" , };
36
37
// Set the type of feedback your service will provide. We are setting it to GENERIC.
37
38
info .feedbackType = AccessibilityServiceInfo .FEEDBACK_GENERIC ;
38
39
// Default services are invoked only if no package-specific ones are present for the type of AccessibilityEvent generated.
39
40
// This is a general-purpose service, so we will set some flags
40
- info .flags = AccessibilityServiceInfo .DEFAULT ;
41
- info .flags = AccessibilityServiceInfo .FLAG_INCLUDE_NOT_IMPORTANT_VIEWS ;
42
- info .flags = AccessibilityServiceInfo .FLAG_REPORT_VIEW_IDS ;
43
- info .flags = AccessibilityServiceInfo .FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY ;
44
- info .flags = AccessibilityServiceInfo .FLAG_RETRIEVE_INTERACTIVE_WINDOWS ;
41
+ info .flags = AccessibilityServiceInfo .DEFAULT | AccessibilityServiceInfo .FLAG_INCLUDE_NOT_IMPORTANT_VIEWS | AccessibilityServiceInfo .FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY | AccessibilityServiceInfo .FLAG_RETRIEVE_INTERACTIVE_WINDOWS ;
45
42
// We are keeping the timeout to 0 as we don’t need any delay or to pause our accessibility events
46
43
info .notificationTimeout = 0 ;
47
44
this .setServiceInfo (info );
48
45
}
49
46
50
47
@ Override
51
48
public void onAccessibilityEvent (AccessibilityEvent event ) {
52
- Log .d (TAG , "onAccessibilityEvent: " + event .toString ());
53
- if ( event . getEventType () == AccessibilityEvent . TYPE_WINDOW_CONTENT_CHANGED ) {
54
- if ( event .getPackageName (). equals ( "com.android.chrome" )) {
55
- getApplicationContext (). startService ( new Intent ( getApplicationContext (), HeadService . class ));
56
- }
49
+ // Log.d(TAG, "onAccessibilityEvent: " + event.toString());
50
+
51
+ AccessibilityNodeInfo source = event .getSource ();
52
+ if ( source == null ) {
53
+ return ;
57
54
}
55
+ // Log.d("Event:: ", event.toString());
56
+ // Log.d("Source:: ", source.toString());
57
+ traverseView (source );
58
+ // if (source.getText() != null)
59
+ // Log.d("Text:: ", source.getText().toString());
58
60
}
59
61
62
+ private void traverseView (AccessibilityNodeInfo info ) {
63
+ for (int i = 0 ; i < info .getChildCount (); i ++) {
64
+ if (info .getChild (i ) != null ) {
65
+ // Log.d("traverse:: ", info.getChild(i).getClassName().toString());
66
+ if (info .getChild (i ).getText () != null )
67
+ Log .d ("traverse text:: " , info .getChild (i ).getText ().toString ());
68
+ traverseView (info .getChild (i ));
69
+ }
70
+ }
71
+ }
60
72
}
0 commit comments