获取实例:
UiDevice.getInstance().pressHome();
getUiDevice().pressHome();(通常不使用,调用函数时会出现空指针异常)
KEYCODE 键盘映射码:
1.KeyEvent 按键事件
2.META KEY
辅助功能键:ALT、SHIFT、CAPS LOCK
UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_A); --(a)
UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_A,1); --(A)
滑动与拖拽:
1步长=5ms 100步长=500ms=半秒
API:
返回值 方法名 描述
boolean
drag(int startX,int startY,int endX,int endY,int steps)
拖动对象从一个坐标拖动到另一个坐标
boolean
swipe(Point[] segments,int segmentSteps)
在点阵列中滑动,5ms一步
boolean
swipe(int startX,int startY,int endX,int endY,int steps)
通过坐标滑动屏幕
void
waitForIdle(long timeout)
自定义超时等待当前应用处于空闲状态
void
waitForIdle()
等待当前应用处于空闲状态,默认等待10s
boolean
waitForWindowUpdate(String packageName,long timeout)
等待窗口内容更新时间的发生
void getCurrentPackageName() 获取当前界面的包名
void dumpWindowHierarchy(String fileName)获取当前界面的布局文件,保存在/data/local/tmp目录下(xml文件)
boolean openNotification()打开通知栏
boolean openQickSettings()打开快速设置