我正在尝试使用我的 Apk 执行滑动命令
process = Runtime.getRuntime().exec("adb shell input swipe 250 300 -800 300");
但在运行期间没有任何反应,也没有发生错误。
我是否必须在 list 中添加任何内容才能使其正常工作?
最佳答案
您只能以root 或shell 用户身份执行/system/bin/input;这在应用程序中不起作用。从应用程序运行时,该命令不应以“adb shell”开头。
以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
关于android - 从 apk 执行 adb shell input swipe 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28337921/