从apk执行adb shell输入滑动命令 [英] execute adb shell input swipe command from apk

查看:368
本文介绍了从apk执行adb shell输入滑动命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用以下命令从我的Apk执行滑动命令

I am trying to execute swipe command from my Apk using


process = Runtime.getRuntime()。exec( adb shell输入滑动250300
-800300);

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 ;这在应用程序中不起作用。从应用程序运行时,该命令不应以 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输入滑动命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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