android 自己app当中实现模拟点击

1.代码实现如下:

Instrumentation inst = new Instrumentation(); inst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN, 500, 500, 0)); inst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_UP, 500, 500, 0));

2.AndroidManifest.xml配置

3.如报错需在AndroidManifest.xml首元素中添加:

xmlns:tools="http://schemas.android.com/tools"

你可能感兴趣的:(android 自己app当中实现模拟点击)