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
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();
For more info, have a look here and here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With