来自应用程序的Adb shell

时间:2015-06-25 09:05:42

标签: android shell adb touchscreen

我想询问是否有办法在应用程序中执行滑动命令

adb shell input touchscreen swipe 200 200 500 200

我想通过按钮点击

1 个答案:

答案 0 :(得分:-1)

如果从手机执行命令,只需input touchscreen swipe 200 200 500 200即可。

将以下方法称为exec("input touchscreen swipe 200 200 500 200");

/**
 * Execute a command in a shell
 * 
 * @param command
 *            command to execute
 * @return the return of the command
 */
public String exec(String command) {
    String retour = "";
    try {
        Runtime runtime = Runtime.getRuntime();

        Process p = runtime.exec(command);

        java.io.BufferedReader standardIn = new java.io.BufferedReader(
                new java.io.InputStreamReader(p.getInputStream()));
        java.io.BufferedReader errorIn = new java.io.BufferedReader(
                new java.io.InputStreamReader(p.getErrorStream()));
        String line = "";
        while ((line = standardIn.readLine()) != null) {
            retour += line + "\n";
        }
        while ((line = errorIn.readLine()) != null) {
            retour += line + "\n";
        }
    } catch (java.io.IOException e) {
        e.printStackTrace();
    }

    return retour;
}