Android: Can I use adb command in my application?

that's all my problem, I want to run Android TestProject in my application, but I don’t know how, and I found that I can start it with a command, for example. "adb shell am instrument -w com.demo.test / android.test.InstrumentationTestRunner" So I tried using in my application: Runtime.getRuntime (). Exec ("adb shell am instrument -w com.demo.test / android.test.InstrumentationTestRunner"), but has:

03-15 02: 24: 42.246: WARN / System.err (3597): java.io.IOException: Error executing exec (). Command: [adb, shell, am, instrument, -w, com.demo.test / android.test.InstrumentationTestRunner] Working directory: null Environment: null ..... 03-15 02: 24: 42.246: WARN / System.err (3597): called: java.io.IOException: permission denied where is my problem?

+3
source share
3 answers

An API already exists for this, Context.startInstrumentation:

. , , . , SDK, , , , - .

+2

Context.startInstrumentation adb. ,

startInstrumentation(new ComponentName("com.example.aatg.tc.test", "android.test.InstrumentationTestRunner"), null, null);
0

The short answer is no. Long answer, curious.

The part after the adb shell command is the part that executes as Runtime.getRuntime().exec(...)

You may be able to achieve what you need using Runtime.getRuntime().exec("instrument -w com.demo.test/android.test.InstrumentationTestRunner"). I have not used it myself, but you may need to pass the arguments as an array. Check the documentation .

-1
source

All Articles