有谁能够使用TouchUtils
类提供的方法在Android Emulator上成功执行单元测试?
我能够使测试通过我的设备,但是当我在模拟器上运行完全相同的测试(和测试套件)时,任何使用TouchUtils
方法的测试始终会引发以下异常:
java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
at android.os.Parcel.readException(Parcel.java:1327)
at android.os.Parcel.readException(Parcel.java:1281)
at android.view.IWindowManager$Stub$Proxy.injectPointerEvent(IWindowManager.java:1196)
at android.app.Instrumentation.sendPointerSync(Instrumentation.java:902)
at android.test.TouchUtils.drag(TouchUtils.java:786)
at android.test.TouchUtils.dragViewTo(TouchUtils.java:633)
...
我已经解锁了键盘锁,甚至运行了其他通过的(非TouchUtils)测试用例。
我没有应用
@UiThreadTest
,也没有运行任何需要代码才能在UI线程上运行的东西。当我注释掉使用
TouchUtils.dragViewTo(...)
的行并放入一个简单的assert(true)
时,测试将运行并通过。有任何想法吗?
最佳答案
如果您的手机已锁定或主屏幕上有其他 Activity ,则会发生这种情况。
关于android - 带有Android模拟器的TouchUtils,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8844687/