'Android AccessibilityService: AccessibilityNodeInfo.ACTION_SET_SELECTION not working properly with multiline fields in Browser apps
I'm working on an app with intense usage of AccessibilityService. The app works great with other Android apps, I can use text selection properly.
The problem comes with multiline fields in browsers: when trying to perform the action AccessibilityNodeInfo.ACTION_SET_SELECTION, it results in a wrong selection.
Here's my example code snippet. It may not be functional, but it helps with stating the issue:
override fun onAccessibilityEvent(event: AccessibilityEvent) {
val nodeInfo = event.source
if (AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED == event.eventType
|| (AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED == event.eventType
&& event.contentChangeTypes and AccessibilityEvent.CONTENT_CHANGE_TYPE_TEXT == AccessibilityEvent.CONTENT_CHANGE_TYPE_TEXT)) {
nodeInfo?.text?.let {
val arguments = Bundle()
arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, 20)
arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, 20)
event.source.performAction(AccessibilityNodeInfo.ACTION_SET_SELECTION, arguments)
}
}
}
As an example of what is happening, when in https://translate.google.com/, if you write:
selection is
not
working
and after writing this text you run the code, after performing the action the caret should be placed somewhere here:
selection is
not
work|ing
but instead, it is placed here:
sel|ection is
not
working
The problem seems to be related to endlines. Everything works great if you just write and select in a single line, but when using multiline, it's not working properly.
Any clue??? Did someone experience the same issue?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
