private void click() {
Log.d(TAG, String.format("Click [%d, %d]", cursorLayout.x, cursorLayout.y));
- AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
if (nodeInfo == null) return;
AccessibilityNodeInfo nearestNodeToMouse = findSmallestNodeAtPoint(nodeInfo, cursorLayout.x, cursorLayout.y + 50);
if (nearestNodeToMouse != null) {
logNodeHierachy(nearestNodeToMouse, 0);
nearestNodeToMouse.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
nodeInfo.recycle();
}
I am using AccessibilityNodeInfo nodeInfo = getRootInActiveWindow(); i am getting null value here
I try
view.createAccessibilityNodeInfo();
By these method i got node. but I got one error seald unreachable like that.
view.getRootView().createAccessibilityNodeInfo();
From the comments I can't seem to get you to show the contents of your service config... I don't want to confuse you with mine, but I feel this example may be more productive.
In your manifest, you'll need to have an accessibility_service_config
file referenced. The name is not important.
<service
android:name="..."
android:enabled="true"
android:label="..."
android:description="..."
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility_service_config" />
</service>
Then res/xml/accessibility_service_config.xml
needs to be something along the lines of
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityFeedbackType="feedbackSpoken"
android:accessibilityFlags="flagDefault|flagReportViewIds"
android:accessibilityEventTypes="typeAllMask"
android:canPerformGestures="false"
android:canRetrieveWindowContent="true"
android:description="..."
/>
It could be that you just need to set canRetrieveWindowContent
to true. Documentation :
Attribute whether the accessibility service wants to be able to retrieve the active window content. This setting cannot be changed at runtime.
Required to allow setting the #AccessibilityServiceInfo#FLAG_RETRIEVE_INTERACTIVE_WINDOWS flag.
May be a boolean value, such as "true" or "false".
Or it could be the contents of needs at least android:accessibilityFlags="flagReportViewIds"
According to the documentation :
This flag requests that the AccessibilityNodeInfos obtained by an AccessibilityService contain the id of the source view. The source view id will be a fully qualified resource name of the form "package:id/name", for example "foo.bar:id/my_list", and it is useful for UI test automation. This flag is not set by default.
I strongly recommend you configure your service properly - I don't recommend copying and pasting my service config verbatim.
Your service config XML is malformed:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"> <-- the angle bracket shouldn't be here -->
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagDefault|flagReportViewIds"
android:canPerformGestures="true"
android:canRetrieveWindowContent="true"
android:accessibilityFeedbackType="feedbackAllMask"
android:notificationTimeout="200"
android:packageNames="com.example.accesibility"
android:canRequestEnhancedWebAccessibility="true"
</accessibility-service>
change it to:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagDefault|flagReportViewIds"
android:canPerformGestures="true"
android:canRetrieveWindowContent="true"
android:accessibilityFeedbackType="feedbackAllMask"
android:notificationTimeout="200"
android:packageNames="com.example.accesibility"
android:canRequestEnhancedWebAccessibility="true"> <-- the angle bracket should be here -->
</accessibility-service>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.