我想在整个Android系统中发送触摸事件。我正在从后台服务发送事件。我的设备已获得 root 权限,并且我已将我的应用程序存储在/system/app 中。
我尝试了检测和system/bin/input选项卡
,检测在应用程序之外不起作用,第二个不会生成错误,但什么也不做。我尝试直接注入(inject)到/dev/input/event2,但没有效果。
代码如下:
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Process process = Runtime.getRuntime().exec("su");//supolicy --live \"allow appdomain input_device dir { ioctl read getattr search open }\" \"allow appdomain input_device chr_file { ioctl read write getattr lock append open }\"");
Runtime.getRuntime().exec ("su chmod 666 /dev/input/event2");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
String cmd = "su /dev/input/event2 ABS_X "+ xPos + " ABS_Y "+ yPos+ "\n";
Runtime.getRuntime().exec(cmd);
}
catch (IOException e) {
e.printStackTrace();
}
}
});
t.start();
我使用这个网站作为引用:https://yhcting.wordpress.com/2010/11/29/linux-writing-input-event-directly/ ,但我不确定我是否正确应用它。如何在/dev/input/event2 中注入(inject)事件?
另外,/dev/input/eventX 是什么?我总是看到它,但不清楚它是输入节点还是只是事件节点的一般指示。最后,我如何知道应该将事件发送到哪个事件节点(event1、event2等)?
编辑:我尝试通过 adb shell su/dev/input/event2 ABS_X xPos ABS_Y yPos 我收到一行内容:未知的用户名或 uid,这是什么意思?
谢谢。
最佳答案
“input”只是android系统中的一个sh脚本。
# Script to start "input" on the device, which has a very rudimentary
# shell.
#
base=/system
export CLASSPATH=$base/framework/input.jar
exec app_process $base/bin com.android.commands.input.Input $*
可以在此处找到有关如何实现“输入”的 Java 代码跟踪:
http://www.srcmap.org/sd_share/4/aba57bc6/AOSP_adb_shell_input_Code_Trace.html
您还可以使用“sendevent”直接注入(inject)触摸事件 input/dev/input/event0
http://ktnr74.blogspot.com/2013/06/emulating-touchscreen-interaction-with.html
关于android - 如何直接发送触摸事件到/dev/input/event?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36342330/