How does Lastpass manage this?!
AccessibilityNodeInfo has a setText() method, but I feel like this is a red herring as the docs state,
Note: Cannot be called from an AccessibilityService. This class is made immutable before being delivered to an AccessibilityService.
Another user asked a similar question a while back, but the recent updates to LastPass prove that it is indeed possible.
Set text in AccessibilityNodeInfo
I found some better solution rather than ACTION_PASTE. I feel ACTION_PASTE makes delay and didn't work properly. ACTION_SET_TEXT works fine for me, check with you.
public void pasteText(AccessibilityNodeInfo node, String text) {
Bundle arguments = new Bundle();
arguments.putString(AccessibilityNodeInfoCompat.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text);
node.performAction(AccessibilityNodeInfoCompat.ACTION_SET_TEXT, arguments);
}
I have figured this out and have it implemented in my app, TapN.
First get the original clipboard contents, save that, copy to the clipboard your content, then paste it, then copy the original content back.
public void inputData(Context c, String data, AccessibilityNodeInfo source) {
try {
String lastClip = clipboard.getPrimaryClip().getItemAt(0).coerceToText(c)
.toString();
} catch (Exception e) {
lastClip = "";
}
Log.d("THE NODE INFO", source.toString());
ClipData clip = ClipData.newPlainText("nfc_input", data);
clipboard.setPrimaryClip(clip);
Log.d("SENDING DATA", Boolean.toString(source.refresh()));
Log.d("SENDING DATA", Boolean.toString(source
.performAction(AccessibilityNodeInfo.ACTION_PASTE)));
ClipData clip = ClipData.newPlainText("nfc_input", lastClip);
clipboard.setPrimaryClip(clip);
}
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