crazyfool
crazyfool

Reputation: 1463

Android - Input Text within app doesn't work

I'm trying to input text into the current running application (not my own) using the adb input text method, this works if I run it from the command prompt such as 'adb input text "Android" and also if I run it from terminal emulator. However the below code run successfully but produces no output on the screen.. I have also tried various other methods to run shell commands which have also not failed but not output any text.. Anyone know what I am doing wrong?

try {
            //Runtime.getRuntime().exec("su");
            Runtime.getRuntime().exec("input text \":\"");
        } catch (IOException e) {
            e.printStackTrace();
        } 

Upvotes: 0

Views: 1180

Answers (3)

salimbenfarhat
salimbenfarhat

Reputation: 65

Maybe you need to use : Runtime.getRuntime().exec("shell input text");

Upvotes: 0

Jon Goodwin
Jon Goodwin

Reputation: 9153

If you run your command from Native executable, it works fine. Build a NDK binary and execute:

char * command = "input text hello%sworld\0";
system( command );//fork and exec input text ...

Upvotes: 0

GioLaq
GioLaq

Reputation: 2547

To inject text into an android app the injector must have

   android.permission.INJECT_EVENTS 

permission, so it must be a system app.

Your Runtime.getRuntime().exec has not this permission.

Upvotes: 1

Related Questions