pinu
pinu

Reputation: 9

Unable to execute sendevent shell command through the android code

I have tried following code snippet to execute the batch of command for sendevent to click the coordinate 44,129 on the emulator. But it is not showing any result. But if i am giving the same batch of command to the shell prompt it is able to click the mentioned coordinate succesfully.

String[] cmmandemulatorarr = {"/system/bin/sendevent /dev/input/event0 3 0 44", "/system/bin/sendevent /dev/input/event0 3 1 129", "/system/bin/sendevent /dev/input/event0 1 330 1", "/system/bin/sendevent /dev/input/event0 0 0 0", "/system/bin/sendevent /dev/input/event0 1 330 0", "/system/bin/sendevent /dev/input/event0 0 0 0", };

         for (int i = 0; i < cmmandemulatorarr.length; i++) {

         Process process =
         Runtime.getRuntime().exec(cmmandemulatorarr[i]);


         BufferedReader reader = new BufferedReader(
         new InputStreamReader(process.getInputStream()));
         int read;
         char[] buffer = new char[4096];
         StringBuffer output = new StringBuffer();
         while ((read = reader.read(buffer)) > 0) {
         output.append(buffer, 0, read);
         }
         reader.close();
         }

    } catch (IOException e) {

        throw new RuntimeException(e);

    }

Is there is anything i am missing here or i have to try something else to get click event on some coordinate through the code.

Note :: I am not getting any exception in the log while executing the code which seems that command is executed successfully.

Regards Pinu

Upvotes: 0

Views: 3166

Answers (2)

Minja
Minja

Reputation: 33

Here you have answer. You need to find touch event id with getevent. Sendevent use decimal space, getevent use hex. This code from first "answer" works on 7.0.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007296

But it is not showing any result.

This is a good thing.

But if i am giving the same batch of command to the shell prompt it is able to click the mentioned coordinate succesfully.

The shell runs with root-level privileges. Your SDK application does not, unless you root your device and arrange to execute your code that way.

Bear in mind that not all devices will have a /system/bin/sendevent command and it can be removed at any time. This is not part of the Android SDK.

i have to try something else to get click event on some coordinate through the code.

This is not possible from the Android SDK for ordinary devices, for obvious security reasons.

Upvotes: 1

Related Questions