簡體   English   中英

無法運行程序“adb”:錯誤=13,權限被拒絕

[英]Cannot run program "adb": error=13, Permission denied

我有一個程序,它必須只執行一個命令

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 命令 throw Android Studio 控制台(但在 Android Studio 控制台中命令不是綠色的)。 如何解決這個問題呢? 此命令正在運行 throw Studio 控制台命令

adb 是您在計算機上使用的工具,“adb shell”在設備(或模擬器)上打開一個 shell,“adb shell command”在其上運行命令。

因此,如果您想在設備上以編程方式運行命令,只需刪除“adb shell”:

Runtime.getRuntime().exec("input tap 0 0")

我得到它是這樣的

 fun commandAdb() {
    InstrumentationRegistry.getInstrumentation().uiAutomation.executeShellCommand("svc wifi disable")
    InstrumentationRegistry.getInstrumentation().uiAutomation.executeShellCommand("svc data disable")
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM