1.往android 板子发送键值
public static void sendKeyEvent(final int KeyCode) {
new Thread() { // 不可在主线程中调用
public void run() {
try {
//Instrumentation inst = new Instrumentation();
//inst.sendKeyDownUpSync(KeyCode);
sendCode(KeyCode);
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
private static void sendCode(int code){
//adb push core code
String command = "input keyevent "+code;
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("su");// the phone must be root,it can exctue the adb command
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command + "\n");
os.writeBytes("exit\n");
os.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
adb shell monkey -p <your.package.name> --throttle 380 -v -s 3500 300000
> C:\monkey_log.txt
http://bbs.gfan.com/android-7683654-1-1.html