我尝试使用以下代码从我的应用程序为另一个应用程序运行“adb shell monkey” :
String[] command = null;
command = new String[] {
"monkey", "-p", "com.example.appname", "-v", "500" };
if(command != null){
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
dumpStream(process.getInputStream());
dumpStream(process.getErrorStream());
LOGGER.error("" + process.exitValue());
if(process.exitValue() == 0 ){
}
}
但它只返回我:
12-11 14:45:47.525: E/MainActivity: main(15436): App /data/data/com.example.app/files/adb -> true
12-11 14:45:47.565: E/MainActivity: main(15436): App adb exit value: 0
12-11 14:45:51.149: E/MainActivity: main(15436): App /data/data/com.example.app/files/adb -> true
12-11 14:46:03.172: E/MainActivity: main(15436): App:Monkey: seed=1387859337757 count=500
12-11 14:46:03.172: E/MainActivity: main(15436): App:AllowPackage: com.example.appname
12-11 14:46:03.172: E/MainActivity: main(15436): App:IncludeCategory: android.intent.category.LAUNCHER
12-11 14:46:03.182: E/MainActivity: main(15436): App:IncludeCategory: android.intent.category.MONKEY
退出代码:9
也许有人知道如何从 android 应用程序运行“猴子”?