Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fill in EditText of any app from (Accessibility)Service?

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

like image 949
r2DoesInc Avatar asked Apr 16 '14 16:04

r2DoesInc


2 Answers

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);
    }
like image 195
Ready Android Avatar answered Sep 21 '22 03:09

Ready Android


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);
}
like image 40
r2DoesInc Avatar answered Sep 20 '22 03:09

r2DoesInc