一.主布局文件 activity_main.xml

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:id="@+id/edit_monkeyPackage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/monkeypackage"
android:maxLines="" >
</EditText> <EditText
android:id="@+id/edit_monkeytime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/monkeytime"
android:maxLines="" >
</EditText> <EditText
android:id="@+id/edit_monkeycount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/monkeycount"
android:maxLines="" >
</EditText>
<Button
android:id="@+id/button_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/button_submit" /> <TextView
android:id="@+id/TextView_01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/TextView_01" /> </LinearLayout>

二. res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MonkeyTest</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="monkeypackage">Input monkeyPackage</string>
<string name="monkeytime">Input monkeyTime</string>
<string name="monkeycount">Input monkeyCount</string>
<string name="button_submit">Submit</string>
<string name="TextView_01">Log Out</string> </resources>

三.主Activity文件 MainActivity.java

package com.example.runmonkeytest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader; import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText; import android.widget.TextView;
import android.widget.Toast; @SuppressLint("NewApi")
public class MainActivity extends Activity { private EditText monkeyPackage;
private EditText monkeyTime;
private EditText monkeyCount;
private TextView LogOut; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main); monkeyPackage = (EditText) findViewById(R.id.edit_monkeyPackage);
monkeyTime = (EditText) findViewById(R.id.edit_monkeytime);
monkeyCount = (EditText) findViewById(R.id.edit_monkeycount);
LogOut = (TextView) findViewById(R.id.TextView_01);
Button button1 =(Button) findViewById(R.id.button_submit); button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Toast.makeText(MonkeyTestActivity.this, "You clicked Button Submit", Toast.LENGTH_SHORT).show();
String monkeyPackageContext = monkeyPackage.getText().toString();
String monkeyTimeContext = monkeyTime.getText().toString();
String monkeyCountContext = monkeyCount.getText().toString(); if(monkeyPackageContext.isEmpty()){
Toast.makeText(MainActivity.this, "input packageName", Toast.LENGTH_SHORT).show();
}else if(monkeyTimeContext.isEmpty()){
Toast.makeText(MainActivity.this, "input pauseTime", Toast.LENGTH_SHORT).show();
}else if(monkeyCountContext.isEmpty()){
Toast.makeText(MainActivity.this, "input Count", Toast.LENGTH_SHORT).show();
}else{
int T = Integer.parseInt(monkeyTimeContext) ;
int C = Integer.parseInt(monkeyCountContext);
String acctionText = "monkey -p "+monkeyPackageContext+" --throttle "+
T + " -s 1000 " + " -v -v -v " + C;// + ">/sdcard/aaaaaa_monkey.log"; Log.d("MonkeyTestActivity", "Toast");
Log.d("MonkeyTestActivity", acctionText);
Toast.makeText(MainActivity.this, acctionText, Toast.LENGTH_SHORT).show(); do_exec(acctionText);
Log.d("MonkeyTestActivity", "Toast2");
} }
}
);
} protected String do_exec(String cmd) {
String s = "\n";
try {
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
s += line + "\n";
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
LogOut.setText(s);
return cmd; } }

四.AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.runmonkeytest"
android:versionCode=""
android:versionName="1.0" > <uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
<uses-permission android:name="andorid.permission.WRITE_EXTERNAL_STORAGE"/> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.runmonkeytest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk
android:minSdkVersion=""
/> </manifest>

执行monkey APK 制作的更多相关文章

  1. 对当前目录下的所有APK包执行Monkey测试,并自动保存Crash日志

    适用平台:Android,代码几个月前写的,有问题请及时回复.本代码会依次安装当前目录下的APK安装包,之后执行Monkey测试,然后卸载掉换下一个,继续重复执行,如出现Cransh,会自动保存在当前 ...

  2. IOS操作系统上执行monkey测试

    IOS操作系统上执行monkey测试 IOS操作系统不像Android系统那么方便,各种限制也比较多,目前我的建议还是直接在模拟器上执行monkey测试.如果需要在真机上面执行,可以参考文档: htt ...

  3. dofile执行ANDROID APK里面的文件

    我使用dofile执行APK文件是不行的,比如 dofile("assets/res/flist")只能先拷贝到writablePath然后再dofile拿到数据后再清除这个临时文 ...

  4. Android 使用DexClassLoader要执行其他apk方法

    Android在apk文件dex文件是java编译出来.class次打包,当然在打包之前会利用自己的协议做一些数据处理,比如优化函数表和变量表.在java程序中是使用classloader来载入这些编 ...

  5. monkey测试跑多个apk|monkey命令

    1.如何跑多个apk的monkey? 黑名单:执行除了黑名单中以外的apk: 白名单:只执行在白名单中的apk. 黑名单的设置方法: a.创建一个名称为blacklist的txt文档,在文件中输入应用 ...

  6. 如何保存不连着电脑跑monkey?如何跑多个APK的monkey?

    哈喽,大家有没有遇到用真机跑monkey的时候,跑到一半结果小手一抖不小心把线碰掉了,结果报告就没获取到啦~ 今天就来解决这个问题 1.如何保存不连着电脑跑monkey? 1).输入命令进入shell ...

  7. Android插件化开发---执行未安装apk中的Service

    欢迎各位增加我的Android开发群[257053751​] 假设你还不知道什么叫插件化开发.那么你应该先读一读之前写的这篇博客:Android插件化开发,初入殿堂 上一篇博客主要从总体角度分析了一下 ...

  8. 老李推荐:第5章7节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 循环获取并执行事件 - runMonkeyCycles

    老李推荐:第5章7节<MonkeyRunner源码剖析>Monkey原理分析-启动运行: 循环获取并执行事件 - runMonkeyCycles   poptest是国内唯一一家培养测试开 ...

  9. Android APP压力测试(二)之Monkey信息自动收集脚本

      Android APP压力测试(二) 之Monkey信息自动收集脚本 前言: 上一篇Monkey介绍基本搬抄官方介绍,主要是为了自己查阅方便.本文重点介绍我在进行Monkey时如何自动收集相关信息 ...

随机推荐

  1. 调试 kafka manager 源码

    前提:可以上外网. kafka manager 是一款优秀的监控 kafka 的工具,采用 scala 语言编写,如何调试 kafka manager 呢? kafka manager 使用 play ...

  2. echarts 去掉 x轴坐标

    symbol:'none', //这句就是去掉点的 smooth:true,

  3. SQL Server2008R2循环语句

    单循环语句 declare @i nvarchar(36) declare @LOCNUM nvarchar(36),@OBJECTTYPE nvarchar(36),@LOCDESC nvarcha ...

  4. HIbernate常见异常(转载)

    SSH阶段常见的异常系列之一hibernate(15条) 异常一 异常一 异常描述: Sax解析异常:cvc-复杂的类型,发现了以元素maping开头的无效内容,应该是以 ‘{“http://www. ...

  5. 20145338 《网络对抗》逆向及Bof基础实验

    逆向及Bof基础实验 实践目标 ·本次实践的对象是一个名为pwn1的linux可执行文件. ·该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串. ·该程序同时包含 ...

  6. Visual Studio 2017 离线安装包

    vs_community.exe --layout D:vs2017offline-en --add Microsoft.VisualStudio.Workload.ManagedDesktop -- ...

  7. 介绍一下Spring Cloud Config

    Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持.使用Config Server,您可以在所有环境中管理应用程序的外部属性.客户端和服务器上的概念映射与Spring ...

  8. Problem 2: Even Fibonacci numbers

    Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting w ...

  9. python "import this"

    The Zen of Python, by Tim Peters Beautiful is better than ugly.Explicit is better than implicit.Simp ...

  10. windows10安装anaconda,配置tensorflow

    1.安装anaconda 3.5.5 默认安装,注意,把添加到path勾选上,其他默认安装(能搜到这篇文章,相信大家都有过变成经验,这些环境变量的重要性就不要窝在多说了) 2.以管理员身份,打开ana ...