I have a accessibility service running for event type "typeViewTextSelectionChanged". I am able to catch this event trigger whenever user selects any text, but how do I get the selected text content from AccessibilityNodeInfo or AccessibilityEvent objects
Asked
Active
Viewed 2,825 times
1 Answers
1
The following goes inside,
onAccessibilityEvent(AccessibilityEvent event){}
And then,
//Get the source
AccessibilityNodeInfo source = event.getSource();
//Grab the parent of the view that fired the event.
AccessibilityNodeInfo rowNode = getListItemNodeInfo(source);
//Using this parent, get references to child node, the selected text
AccessibilityNodeInfo textNode = rowNode.getChild(0);
//Get the text values
String text = textNode.getText();
OR
Alternatively in your case, the following should work just fine. Since, it's a "typeViewTextSelectionChanged" event, it's obviously from an EditText.
String text=event.getText();

Darshan Miskin
- 844
- 14
- 25
-
I can't seem to find any documentation for getListItemNodeInfo, could you please link to where you seen that? – Jayce Jul 31 '17 at 19:09
-
3getListItemNodeInfo is a method from here: https://android.googlesource.com/platform/development/+/master/samples/ApiDemos/src/com/example/android/apis/accessibility/TaskBackService.java – hemisphire Apr 16 '18 at 17:39