无法从我的app android中输入“enter”键事件

时间:2016-04-08 07:05:34

标签: android keyevent accessibilityservice adb-shell

我想从我的应用程序中以编程方式输入“输入”键事件。

我已经尝试过使用abd shell命令以及使用AccessibilityService,但没有找到运气。

Similar question was asked here as well

下面是我用来执行adb shell命令的代码:

try {
    Runtime runtime = Runtime.getRuntime();

    Process p = runtime.exec("input keyevent 66");

    BufferedReader standardIn = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader errorIn = new BufferedReader(new InputStreamReader(p.getErrorStream()));

    String output = "";
    String line;
    while ((line = standardIn.readLine()) != null) {
        output += line + "\n";
    }
    while ((line = errorIn.readLine()) != null) {
        output += line + "\n";
    }

    Log.d("output", "" + output);
} catch (IOException e) {
    e.printStackTrace();
}

我得到以下输出:

sh: resetreason: can't execute: Permission denied

有人请帮帮我。

如果有人知道如何使用AccessibilityService实现它,请告诉我。

提前致谢!

1 个答案:

答案 0 :(得分:-1)

添加此<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />权限&amp;再试一次。