无法通过Android code来执行的SendEvent shell命令 [英] Unable to execute sendevent shell command through the android code

查看:198
本文介绍了无法通过Android code来执行的SendEvent shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试以下code段执行批处理命令,为的SendEvent点击模拟器的坐标44129。但它不显示任何结果。但是,如果我给同批命令外壳及时它能够点击提到成功地协调

的String [] = cmmandemulatorarr {/系统/斌/的SendEvent的/ dev /输入/ EVENT0 3 0 44
                /系统/斌/的SendEvent的/ dev /输入/ EVENT0 3 1 129
                /系统/斌/的SendEvent的/ dev /输入/ EVENT0 1 330 1
                /系统/斌/的SendEvent的/ dev /输入/ EVENT0 0 0 0
                /系统/斌/的SendEvent的/ dev /输入/ EVENT0 1 330 0
                /系统/斌/的SendEvent的/ dev /输入/ EVENT0 0 0 0};

 的for(int i = 0; I< cmmandemulatorarr.length;我++){         工艺过程=
         调用Runtime.getRuntime()EXEC(cmmandemulatorarr [I])。
         读者的BufferedReader =新的BufferedReader(
         新的InputStreamReader(process.getInputStream()));
         INT读;
         的char []缓冲区=新的char [4096];
         StringBuffer的输出=新的StringBuffer();
         而((读取= reader.read(缓冲液))大于0){
         output.append(缓冲,0,读);
         }
         reader.close();
         }    }赶上(IOException异常五){        抛出新的RuntimeException(E);    }

时有什么我是缺少在这里或者我必须尝试别的东西来获取点击通过code一些坐标事件。

请注意::在执行code这似乎命令执行成功,我没有得到任何异常在日志中。

问候
Pinu酒店


解决方案

  

但它不显示任何结果。


这是一件好事。


  

但是,如果我给同批命令外壳及时它能够点击提到成功地协调


外壳具有root级别的权限运行。您的SDK应用程序不会,除非你铲除你的设备,并安排执行你的code的方式。

请记住,并非所有的设备将有一个 /系统/斌/的SendEvent 命令,它可以在任何时候被删除。这不是Android SDK的一部分。


  

我要尝试其他的东西来获得点击通过code一些坐标事件。


这是不可能的从Android SDK对于普通设备,为明显的安全理由。

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

解决方案

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.

这篇关于无法通过Android code来执行的SendEvent shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆