android 执行monkey指令的方法
来源:互联网 发布:汇量科技 知乎 编辑:程序博客网 时间:2024/06/15 10:32
android 执行外部指令 monkey指令的方法
在我做手机测试apk时遇到一个问题就是在android手机上如何执行monkey指令。其实android系统是有exec()方法来执行外部指令。
废话不多说,咱还是直接上代码。
private static StringBuilder sResult = new StringBuilder("");public static int execCommand(String command1) { command1="monkey --throttle 500 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -v " + "-p com.android.contacts " + "-p com.android.dialer " + "-p com.android.calendar " + "-p com.mediatek.todos " + "-p com.android.deskclock " + "-p com.android.gallery3d " + "-p com.android.music " + "-p com.mediatek.filemanager " + "-p com.mediatek.videoplayer " + "-p com.android.settings " + "-p com.android.systemui "+ "1000000"; android.util.Log.i(TAG2," MainActivity execCommand() command1="+command1); sResult.delete(0, sResult.length()); Process process = null; try { //执行指令 process = Runtime.getRuntime().exec(command1); } catch (Exception ex) { ex.printStackTrace(); } if (process == null) { return -1; } // Matcher m = Pattern.compile("[0-9]").matcher(process.toString()); StringBuffer bf = new StringBuffer(64); while (m.find()) { bf.append(m.group()); } savePid(Integer.parseInt(bf.toString(), 10)); //打印log的位置文件 String path ="/MonkeyTestResultERROR.txt"; String path2 ="/MonkeyTestResult.txt"; new StreamGobbler(process.getErrorStream(),"ERROR",path).start(); new StreamGobbler(process.getInputStream(), "STDOUT",path2).start(); return 0; }
在我代码就绪和该给的权限都给了之后可是apk还是不能直接安装到手机上,后来查明是因为系统签名在作祟。因为androidmanifest.xml文件使用了 android:sharedUserId=”android.uid.system”,进行系统签名之后才能安装使用。
阅读全文
0 0
- android 执行monkey指令的方法
- android 入门 Monkey 指令说明
- Android Monkey测试简易实用有效指令
- 【Android M】Monkey命令源码及是否处于monkey测试的判断方法
- Android和iOS Monkey方法
- android monkey测试方法实践
- Android的monkey测试
- Android的monkey用法
- Android的monkey测试
- Android的monkey测试
- android Monkey的使用
- android Monkey的使用
- Android的monkey测试
- Android的monkey测试
- Android的monkey测试
- Android的monkey用法
- Android的Monkey
- Android monkey的使用
- mysql between and 和in效率问题
- C++实训2-2
- Java之深入JVM(3)
- (Ext / Js) ajax 跨域请求发送两次解决方案
- Unity Shader 学习笔记(9) 渐变纹理、遮罩纹理
- android 执行monkey指令的方法
- 定义一个圆形类,实现圆的的面积计算
- api设计干货
- (二)Git的安装与配置
- centos-搭建https服务器
- Linux基本指令、文件管理权限及Linux重要目录的整理
- Mac使用 matplotlib 画图 => RuntimeError: Python is not installed as a framework
- tomcat虚拟路径——webapps目录外部静态资源访问
- 特殊体系的相平衡和精馏模拟计算.pdf