clickLongOnScreen(x,y)和clickLongOnView(v)返回“注入另一个应用程序需要INJECT_EVENTS权限”

时间:2014-02-28 14:53:45

标签: java android robotium

使用com.bitbar.recorder.extensions.ExtSolo测试长按屏幕并在视图上返回java.lang.SecurityException。

View v = findViewById("com.view.id");

int location[] = new int[2];
v.getLocationOnScreen(location);

clickLongOnScreen(location[0], location[1]);

clickLongOnView(v);

完整的错误消息:

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:1203)
at android.app.Instrumentation.sendPointerSync(Instrumentation.java:902)
at com.jayway.android.robotium.solo.Clicker.clickLongOnScreen(Clicker.java:117)
at com.jayway.android.robotium.solo.Clicker.clickOnScreen(Clicker.java:154)
at com.jayway.android.robotium.solo.Solo.clickLongOnView(Solo.java:933)
at com.bitbar.recorder.extensions.ExtSolo.a(ExtSolo.java:3525)
at com.bitbar.recorder.extensions.a.a(Clicker.java:63)
at com.bitbar.recorder.extensions.a.a(Clicker.java:84)
at com.bitbar.recorder.extensions.ExtSolo.clickLongOnView(ExtSolo.java:1394)
at com.ui.android.test.UI.longClickAndDrag(UI.java:174)
at com.ui.android.test.Test_1_17_006_LONGPRESS(Test.java:1153)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:545)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)

1 个答案:

答案 0 :(得分:1)

当您尝试将事件发送到不属于您的应用程序的窗口时,会抛出该异常。您需要找出导致您的应用无法成为目标的原因。