Android在代码中常用的模拟点击、滑动事件方案有Instrumentation 、用Runtime发送input或sendevent等。对这几种方案测试效果如下。
Instrumentation 和input
Instrumentation 和input 不用系统签名时可作用于自身应用。向全局使用(对其他应用也生效)时,需要添加
android:sharedUserId="android.uid.system"
并进行系统签名。
sendevent方案
代码中调用Runtime.getRuntime().exec 执行sendevent时。
用用su执行:
不用su时:
此方案需要root,开放的权限过大。可先放弃。