Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set text in AccessibilityNodeInfo

I'm developing an Android Accessibility Service. I got an AccessibilityNodeInfo that represents an EditText. Is possibile to edit the contained text?

I tried with mynode.setText("aaa") but i get IllegalStateException as described in official documentation http://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html

Any ideas? Thanks

like image 885
user2196877 Avatar asked Mar 21 '13 20:03

user2196877


1 Answers

You can use ACTION_SET_TEXT for >= android 21. Here is the example of it:

AccessibilityNodeInfo source = event.getSource();
if (source != null & event.getClassName().equals("android.widget.EditText")) {
    Bundle arguments = new Bundle();
    arguments.putCharSequence(AccessibilityNodeInfo
            .ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "android");
    source.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments);
}
like image 162
Anton Kashpor Avatar answered Nov 14 '22 03:11

Anton Kashpor