0

I need to know, can we execute adb shell script programtically in android, because i need that script running when application start for be as a device owner in kiosk mode feature like this below :

adb shell dpm set-device-owner com.test/.AdminReceiver

Thanks in advance

Jhon Doe
  • 21
  • 5

1 Answers1

0

Your best choice would be Runtime class, it can be used like:

String yourCommand = "adb shell dpm set-device-owner com.test/.AdminReceiver";
Runtime.getRuntime().exec(yourCommand);
bmaciejm
  • 101
  • 7
  • You should fix your variable names to be consistent. – Code-Apprentice Oct 25 '22 at 08:09
  • 1
    You are right, thanks for pointing this out. – bmaciejm Oct 25 '22 at 08:10
  • i got this error sir .. Cannot run program "adb": error=13, Permission denied – Jhon Doe Oct 25 '22 at 09:38
  • 1
    Actually it looks like as long as the approach mentioned above will work for executing shell commands in general it is not that simple when it comes to `adb` commands specifically. For more detailed explanation it was already answered here https://stackoverflow.com/a/52682468/4153947 and here https://stackoverflow.com/questions/44871391/run-adb-on-the-device-itself-i-e-as-if-it-were-the-pc-issuing-the-commands Thus I would propose that you can mark your question as duplicate and read the above threads. – bmaciejm Oct 25 '22 at 14:12
  • @JhonDoe I think you will need to root your phone in order to execute `adb` from an app. – Code-Apprentice Oct 26 '22 at 17:41