0

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

pinu
  • 9
  • 1
  • 2

2 Answers2

1

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • But i am trying on emulator which is having root level privileges. And do we have any other way to implement auto click on some part of screen ? – pinu Aug 10 '11 at 14:03
  • "But i am trying on emulator which is having root level privileges" -- SDK applications do not have root-level privileges, even on an emulator. "And do we have any other way to implement auto click on some part of screen" -- fortunately, no. – CommonsWare Aug 10 '11 at 14:11
0

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.

Minja
  • 33
  • 5