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配置
<uses-permission android:name="android.permission.INJECT_EVENTS" tools:ignore="ProtectedPermissions" />
3.如报错需在AndroidManifest.xml首元素中添加:
xmlns:tools="http://schemas.android.com/tools"
网友评论