How to get selected text from AccessibilityNodeInfo

I have an availability service running for the event type "typeViewTextSelectionChanged". I can catch this event trigger whenever the user selects any text, but how to get selected text content from AccessibilityNodeInfo or AccessibilityEvent objects

+7
android accessibilityservice
source share
1 answer

Inside is

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 fine. Since this is an event of type typeViewTextSelectionChanged, this is obviously from an EditText.

 String text=event.getText(); 

For more information, look here and here.

+1
source share

All Articles