相关文章推荐
威武的南瓜  ·  adb logcat -g - CSDN文库·  3 小时前    · 
淡定的盒饭  ·  清除adb logcat缓存_adb ...·  3 小时前    · 
踏实的茄子  ·  清除adb ...·  11 小时前    · 
酷酷的茶叶  ·  ADB ...·  11 小时前    · 
天涯  ·  低代码平台架构图-掘金·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a program, which must execute only one command

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")

But I'm getting an error

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) 

Although I've added adb to path into properties on Windows and can run abd commands throw Android Studio console (but in Android Studio console command is not green). How to solve this problem? This command is working throw Studio console command

adb is a tool you use on your computer, "adb shell" opens a shell on the device (or emulator), and "adb shell command" runs the command on it.

So if you want to run the command programmatically on the device, just remove "adb shell":

Runtime.getRuntime().exec("input tap 0 0")
                @ Cédric LE MOING I followed your answer for the command adb shell wm overscan", "0,0,0,-220 but the only thing it did was stop the message of exception of error no 13 from coming, it didn't execute anything
– Anubhav Pandey
                Jan 7, 2020 at 6:19

I got it like this

 fun commandAdb() {
    InstrumentationRegistry.getInstrumentation().uiAutomation.executeShellCommand("svc wifi disable")
    InstrumentationRegistry.getInstrumentation().uiAutomation.executeShellCommand("svc data disable")
                Is it still working? Because Android Studio gives me import error of InstrumentationRegistry and executeShellCommand seems not to be visible in IDE's prompt...
– The_Long_Distance_Runner
                Sep 9, 2022 at 9:32
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.