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

2019-10-28  本文已影响0人  zuopiezi5200

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"

上一篇下一篇

猜你喜欢

热点阅读