繁体   English   中英

长按Android里面的应用程序

[英]Long press Android inside Application

我正在尝试使用 ADB 在 Android 设备上模拟长按。

我阅读了本指南: http : //ktnr74.blogspot.it/2013/06/emulating-touchscreen-interaction-with.html

而且我知道它适用于 Android 的 UI,但它在应用程序中不起作用。

特别是,我试图在应用程序的文本字段上模拟长按。

编辑:首先,您需要 root 来执行此操作。 在运行时请求 root:

public static Process requestPermission() {
    try {
        return Runtime.getRuntime().exec("su");
    } catch (IOException e) {
        LOGGER.error("The phone needs root: ", e.getMessage());
        return null;
    }
}

然后:

Process process = SystemUtils.requestPermission();
DataOutputStream os = new DataOutputStream(process.getOutputStream());

cmd = "/system/bin/input swipe 100 1650 600 1650\n"; //Example

os.writeBytes(cmd);
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();

命令和默认来源是:

text <string> (Default: touchscreen)
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)

您可以在此处找到“adb shell keyevent”命令

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM