从 apk 执行 adb shell input swipe 命令 [英] execute adb shell input swipe command from apk
问题描述
我正在尝试使用
process = Runtime.getRuntime().exec("adb shell input swipe 250 300-800 300");
process = Runtime.getRuntime().exec("adb shell input swipe 250 300 -800 300");
但在运行时什么也没有发生,也没有错误发生.
but nothing happens and no error occurs during runtime.
我是否必须在清单中添加任何内容才能使其工作?
Do i have to add anything in manifest to get it to work?
推荐答案
您只能以 root 或 shell<执行 /system/bin/input/em> 用户;这在应用程序中不起作用.从应用程序运行时,该命令不应以adb shell"开头.
You can only execute /system/bin/input as the root or shell user; this will not work in an app. The command should not start with "adb shell" when running from the app.
以 root 身份运行命令:
To run the command as root:
Process su = null;
try {
su = Runtime.getRuntime().exec("su");
su.getOutputStream().write("input swipe 250 300 -800 300\n".getBytes());
su.getOutputStream().write("exit\n".getBytes());
su.waitFor();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (su != null) {
su.destroy();
}
}
您还应该查看处理 su 命令的第三方库:https://android-arsenal.com/details/1/451
You should also check out third party libraries for handling su commands: https://android-arsenal.com/details/1/451
这篇关于从 apk 执行 adb shell input swipe 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!