I want to change text inside EditText within Accessibility service. My code is:
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
final AccessibilityNodeInfo source = event.getSource();
if (source != null & event.getClassName().equals("android.widget.EditText")) {
AccessibilityNodeInfo currentSource = source;
ClipboardManager clipboard = (ClipboardManager) this.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", "TestData");
clipboard.setPrimaryClip(clip);
currentSource.performAction(AccessibilityNodeInfo.ACTION_PASTE);
And it works well. When user presses on EditText it changes to "TestData". After that shows dialog with button. And I want to change text through pressing the button.
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setTitle("Test dialog");
builder.setMessage("Content");
builder.setPositiveButton("User", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
ClipboardManager clipboard = (ClipboardManager) getApplication().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", "Test Username");
clipboard.setPrimaryClip(clip);
currentSource.performAction(AccessibilityNodeInfo.ACTION_PASTE);
dialog.dismiss();
}
});
Clipboard refreshes if press the button, but text inside EditText doesn't.
I've resolve my problem with timer thread. It helped me, because Accessibility service works on different devices with some "delay".