android - java.lang.SecurityException : Permission Denial: getIntentSender() when using UiAutomation in a test 错误

标签 android android-testing android-uiautomator

每当我尝试使用 UiAutomation在通过 getInstrumentation().getUiAutomation() 进行的任何测试中,进程崩溃并出现以下异常:

java.lang.SecurityException: Permission Denial: getIntentSender() from pid=30334, uid=2000, (need uid=1000) is not allowed to send as package android
        at android.os.Parcel.readException(Parcel.java:1540)
        at android.os.Parcel.readException(Parcel.java:1493)
        at android.app.IUiAutomationConnection$Stub$Proxy.disconnect(IUiAutomationConnection.java:225)
        at android.app.UiAutomation.disconnect(UiAutomation.java:240)
        at android.app.Instrumentation.finish(Instrumentation.java:197)
        at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:575)
        at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1837)

知道为什么吗?我通过 Android Studio 使用 Gradle,尝试了各种版本,直接通过 adb 调用它,即使没有任何外部依赖(显然至少有 SDK 18)......总是崩溃。

这是我找到的唯一官方示例:https://www.youtube.com/watch?v=_SlBHUW0ybM

最佳答案

这不是 UIAutomator 为何未捕获错误的答案,而是我发现的一种可能的解决方法。当可访问性服务打开时,我无法获取 UIAutomator 转储,因为我收到了您描述的错误。当我在辅助功能设置中关闭 TalkBack 和/或切换访问时,我不再收到权限拒绝错误并且 UIAutomator 转储成功运行。不确定这是否对您有帮助,但我每次都可以在 Lollipop (Nexus 5) 中启用无障碍服务来重现您的问题。

关于android - java.lang.SecurityException : Permission Denial: getIntentSender() when using UiAutomation in a test 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27132799/

相关文章:

android - Android Gradle 插件中的 testOptions.animationsDisabled 属性有什么作用?

android - Robolectric 3.0 测试 fragment

java - 如何测试 Android 上的预测键盘是否被禁用?

android - 有没有办法通过 adb 获取当前 Activity 的布局和 View ?

Android相机byte[]数组转2D数组

android - 制作跨平台 RTMP 流媒体/播放应用程序的正确方法。 Phonegap livu插件?

Android 测试 BuildConfig 字段

java - Android JSON 对象返回 null

java - egl_emulation eglsurfaceattrib 未使用流媒体播放器实现

android - 如何检测 uiautomator 中的抬头通知?