2

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

0

1 Answer 1

2

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);
5
  • You should fix your variable names to be consistent. Commented Oct 25, 2022 at 8:09
  • 1
    You are right, thanks for pointing this out.
    – bmaciejm
    Commented Oct 25, 2022 at 8:10
  • i got this error sir .. Cannot run program "adb": error=13, Permission denied
    – Jhon Doe
    Commented Oct 25, 2022 at 9: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 stackoverflow.com/a/52682468/4153947 and here stackoverflow.com/questions/44871391/… Thus I would propose that you can mark your question as duplicate and read the above threads.
    – bmaciejm
    Commented Oct 25, 2022 at 14:12
  • 1
    @JhonDoe I think you will need to root your phone in order to execute adb from an app. Commented Oct 26, 2022 at 17:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.