Android跑Monkey必备代码

防止Monkey点击状态栏,虚拟按键

首先是手机全屏动态隐藏状态栏和虚拟按键(本人使用nexus6p)

adb shell settings put global policy_control immersive.full=*

恢复:adb shell settings put global policy_control null

然后取消音量键返回键等事件(防止点开音量键 然后进入设置界面 等等。。。)

  @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch(keyCode){
            case KeyEvent.KEYCODE_HOME:return true;
            case KeyEvent.KEYCODE_BACK:return true;
            case KeyEvent.KEYCODE_CALL:return true;
            case KeyEvent.KEYCODE_SYM: return true;
            case KeyEvent.KEYCODE_VOLUME_DOWN: return true;
            case KeyEvent.KEYCODE_VOLUME_UP: return true;
            case KeyEvent.KEYCODE_STAR: return true;
        }
        return super.onKeyDown(keyCode, event);
    }

然后就可以开始: adb shell monkey -p ***.***.*** -vvv 1000 > monkey1000.txt

你可能感兴趣的:(android)