android - 从 apk 执行 adb shell input swipe 命令

标签 android shell apk adb

我正在尝试使用我的 Apk 执行滑动命令

process = Runtime.getRuntime().exec("adb shell input swipe 250 300 -800 300");

但在运行期间没有任何反应,也没有发生错误。

我是否必须在 list 中添加任何内容才能使其正常工作?

最佳答案

您只能以rootshell 用户身份执行/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/

相关文章:

git - 如何使用SSH登录Github并在命令行中创建新的存储库?

打印可用内存和总内存的 Linux 基本脚本

上传到 Google Play 时 android apk 未对齐

java - Android 开发新波士顿 *电子邮件*

Android Pusher 无效签名 - 客户端

android - 如何在android中完成所有 Activity 并关闭应用程序?

android-studio - 错误:APK打包期间文件重复

android - 如何使用 sqlite 查询获取当前月份或指定月份的日期?

linux - 为什么这个 awk 命令不起作用

android - 如何知道 APK 文件是否比安装的更新?