我有一个程序,该程序只能执行一个命令
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Runtime.getRuntime().exec("adb shell input tap 0 0")
}
}
但是我遇到了错误
Process: com.example.tomfo.pokerclicker, PID: 11578
java.io.IOException: Cannot run program "adb": error=13, Permission denied
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
at java.lang.Runtime.exec(Runtime.java:695)
at java.lang.Runtime.exec(Runtime.java:525)
at java.lang.Runtime.exec(Runtime.java:422)
at com.example.tomfo.pokerclicker.MainActivity$onCreate$1.run(MainActivity.kt:14)
at java.util.TimerThread.mainLoop(Timer.java:562)
at java.util.TimerThread.run(Timer.java:512)
Caused by: java.io.IOException: error=13, Permission denied
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
at java.lang.ProcessImpl.start(ProcessImpl.java:132)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at java.lang.Runtime.exec(Runtime.java:695)
at java.lang.Runtime.exec(Runtime.java:525)
at java.lang.Runtime.exec(Runtime.java:422)
at com.example.tomfo.pokerclicker.MainActivity$onCreate$1.run(MainActivity.kt:14)
at java.util.TimerThread.mainLoop(Timer.java:562)
at java.util.TimerThread.run(Timer.java:512)
尽管我已将adb添加到Windows属性的路径中,并且可以运行abd命令抛出Android Studio控制台(但在Android Studio控制台中命令不是绿色的)。如何解决这个问题呢?该命令正在运行throw Studio控制台命令
答案 0 :(得分:3)
adb是您在计算机上使用的工具,“ adb shell”在设备(或仿真器)上打开外壳,然后“ adb shell命令”在其上运行命令。
因此,如果要在设备上以编程方式运行命令,只需删除“ adb shell”:
Runtime.getRuntime().exec("input tap 0 0")