开发者

Android:Can I use adb command in my app?

all here is my problem,I want to start an android TestProject in my app,but 开发者_C百科I don't konw how,and I found that I can start it with command ,e.g. "adb shell am instrument -w com.demo.test/android.test.InstrumentationTestRunner" So I have tried use in my app :Runtime.getRuntime().exec("adb shell am instrument -w com.demo.test/android.test.InstrumentationTestRunner");but have:

03-15 02:24:42.246: WARN/System.err(3597): java.io.IOException: Error running 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): Caused by: java.io.IOException: Permission denied where is my problem?


There is already an API for this, Context.startInstrumentation:

This is how the shell command is implemented. You can't do anything more by launching a shell command than you can do in your own process. Also, no shell commands are part of the SDK, so anything you do with it is likely to break at some point on different devices or versions of the platform.


You should use Context.startInstrumentation, instead of adb. For example, from your Activity, run

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


Short answer - no. Long answer, kinda.

The part after the 'adb shell' command is the part that is executed, much like Runtime.getRuntime().exec(...)

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜