大佬教程收集整理的这篇文章主要介绍了android – 如何在向ActivityInstrumentationTestCase2测试发送触摸时修复INJECT_EVENT权限异常,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
public class myTest extends ActivityinstrumentationTESTCase2<MyActivity> { public myTest(String Name) { super("com.mypackage.activities",MyActivity.class); setName(Name); } public void testTap() throws Throwable { //required by MotionEvent.obtain according to JavaDocs long downTime = Sy@R_404_2407@Clock.uptimeMillis(); long eventTime = Sy@R_404_2407@Clock.uptimeMillis(); instrumentation i = getinstrumentation(); //Setup the info needed for our down and up events to create a tap MotionEvent downevent = MotionEvent.obtain(downTime,eventTime,MotionEvent.ACTION_DOWN,300,20,0); MotionEvent upEvent = MotionEvent.obtain(downTime,MotionEvent.ACTION_UP,0); //Send the down/up tap event i.sendPointerSync(downevent); i.sendPointerSync(upEvent); //Delay to see the results Thread.currentThread().sleep(3000); } }
这引发了一个
Java.lang.SecurityException:注入另一个应用程序需要INjeCT_EVENTS权限
在i.sendPointerSync()调用上.
我也尝试过view.onTouchEvent(event)和view.dispatchTouchEvent(event)但没有成功.
我唯一能想到的是,如果这个例子在正在测试的项目中有效.这看起来很糟糕,因为建议将测试分离到不同的项目,并能够从构建服务器运行它们,例如:
adb -e sHell am instrument -w com.mypackage.activities.test/android.test.instrumentationTestRunner
以上是大佬教程为你收集整理的android – 如何在向ActivityInstrumentationTestCase2测试发送触摸时修复INJECT_EVENT权限异常全部内容,希望文章能够帮你解决android – 如何在向ActivityInstrumentationTestCase2测试发送触摸时修复INJECT_EVENT权限异常所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。