0

There is a focus on the field , in the browser , or notepad . When I plan to offer NFC, I want to force to insert text into the focused field . I know how to read NFC tag and add it to the clipboard . But how to make paste this text into an external application for the selected field ? Unfortunately I have not found how to do it using the clipboard manager. Tell me in what direction I move? Maybe using the keyboard ?

Maxim
  • 23
  • 2

1 Answers1

0

I'd suggest emulating keypresses.

new Thread(new Runnable() {         
        @Override
        public void run() {
            try {
            Instrumentation inst = new Instrumentation();
            for ( int i = 0; i < 10; ++i ) {
                inst.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
                Thread.sleep(2000);
                inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
                Thread.sleep(2000);
            }
            }
            catch(InterruptedException e){
            }
        }   
    }).start();

Android simulate key press

There's probably a way for you to emulate ctrl+v, which, despite not being on the default keyboards, does work on most devices.

Community
  • 1
  • 1
Daniël van den Berg
  • 2,197
  • 1
  • 20
  • 45