【问题标题】:How do root apps access the ui of other apps?root 应用如何访问其他应用的 ui?
【发布时间】:2019-06-11 14:59:43
【问题描述】:

我正在寻找构建一个应用程序,该应用程序(具有 root 权限)可以访问另一个应用程序上的 ui 并单击屏幕上的按钮。我已经看到许多宏应用程序和一些“机器人”应用程序都做到了这一点。我知道他们使用“设备管理员”,并且我看到一些需要“覆盖其他应用程序”的权限。我不是在寻找全面的指南,而且我知道我必须使用某种 ocr 软件来处理 ui 元素。有人可以给我一些指示吗?示例:https://forum.xda-developers.com/showthread.php?t=2241770 谢谢你的帮助! 泰纳

【问题讨论】:

    标签: android apk root cross-application


    【解决方案1】:

    我不知道他们是怎么做到的,但一种可能的方法是通过input shell 命令。我希望普通程序没有使用它的权限,但adb shell 有,并且有根程序可能会。用法打印如下:

    Usage: input [<source>] <command> [<arg>...]
    
    The sources are:
          mouse
          keyboard
          joystick
          touchnavigation
          touchpad
          trackball
          stylus
          dpad
          touchscreen
          gamepad
    
    The commands and default sources are:
          text <string> (Default: touchscreen) [delay]
          keyevent [--longpress] <key code number or name> ... (Default: keyboard)
          tap <x> <y> (Default: touchscreen)
          swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
          press (Default: trackball)
          roll <dx> <dy> (Default: trackball)
    

    你会做类似的事情

    List<String> commandLine = Arrays.asList("input touchscreen swipe 500 10 500 500 100".split(" "));
    Process process = Runtime.getRuntime().exec(commandLine);
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    

    如Any way to run shell commands on android programmatically? 中所述。 (我稍微调整了一下,还没有实际测试过,所以可能需要一些摆弄。)

    请注意,它不能让您查看按钮在哪里,因此您必须事先知道自己在做什么。

    您也可以尝试Instrumentation,如下所述:Android simulate key press

    【讨论】:

    • 您可能需要在命令中添加sudo;不知道你如何在 Android 上调用超级权限。
    • 感谢您的回答,它让我走上了正轨!
    猜你喜欢
    • 2015-03-06
    • 1970-01-01
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多