Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 560
Strangelove Avatar asked Feb 13 '19 22:02

Strangelove


1 Answers

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")
like image 158
Cédric LE MOING Avatar answered Sep 21 '22 20:09

Cédric LE MOING