1

I have requirement like i need to take a UI dump of each window that appears on my android app to verify resource-id given is unique.

basically i want do what this command "adb shell uiautomator dump" does inside the android app.

1
  • 4
    You cannot run adb commands from an app, except perhaps on rooted devices. Commented Feb 18, 2017 at 23:29

1 Answer 1

2

@CommonsWare may be correct. But I tested the code below on two non-rooted devices and I was able to get an output. (Nexus 6P and Samsung S5)

@Gokul

I found the key was to NOT specify "adb shell" beforehand as it must be in the path already and I get a permission error if I attempt to use it.

Doing something like this:

String command = "service list";
Process process = Runtime.getRuntime().exec(command);

Worked for me running in a unit test on two real non-rooted devices.

This produces the same results as running the command: "adb shell service list" from the command prompt.

2
  • Runtime.getRuntime().exec("pm grant package.name.here android.permission.SYSTEM_ALERT_WINDOW"); wont work
    – ralphgabb
    Commented Jun 18, 2019 at 5:10
  • Not all commands work. Some require rooted phones. Later operating systems further limit what options are available here. (Especially things that try to access information about other applications). You cannot dynamically grant your app specific permissions this way either. That's a huge security risk (maybe on a rooted phone, i'm not sure).
    – Dave
    Commented Jul 23, 2019 at 17:20

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