Tuesday, 24 December 2019

How click in UI window on Android Oreo and higher with AccessibilityService?

I have followed this suggestion to unistall my app programatically and everything works fine until Android 7.1, but after when I tested the same on Android 8.1 and 9, this seems to not work (none click is performed on Ui window). What's happening? some update was made about this in these versions?

main code:

MyAccessibility:

public void onAccessibilityEvent(AccessibilityEvent event) {

 AccessibilityNodeInfo source = event.getSource();

    if (source == null) {
        return;
    }

    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {

        List<AccessibilityNodeInfo> list = source.findAccessibilityNodeInfosByViewId("android:id/button1");
        for (AccessibilityNodeInfo node : list) {
            node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
        }
   }

}

XML (main):

<service
            android:name=".MyAccessibility"
            class=".MyAccessibility"
            android:enabled="true"
            android:exported="false"
            android:label="@string/accessibility_service_label"
            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
            <intent-filter>
                <action
                    android:name=".MyAccessibility"
                    android:value=".MyAccessibility" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.accessibilityservice.AccessibilityService" />
            </intent-filter>

            <meta-data
                android:name="android.accessibilityservice"
                android:resource="@xml/accessibility_service_config" />
        </service>

XML (AccessibilityService):

<?xml version="1.0" encoding="utf-8"?>

<accessibility-service
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:accessibilityEventTypes="typeAllMask"
    android:accessibilityFeedbackType="feedbackAllMask"
    android:accessibilityFlags="flagDefault|flagIncludeNotImportantViews|flagReportViewIds"
    android:canPerformGestures="true"
    android:canRetrieveWindowContent="true"
    android:description="@string/accessibility_service_description"
    android:notificationTimeout="100"
    tools:ignore="UnusedAttribute" />


from How click in UI window on Android Oreo and higher with AccessibilityService?

No comments:

Post a Comment