How to register broadcast receiver inside instrumentation?

后端 未结 2 618
攒了一身酷
攒了一身酷 2021-01-23 09:33

I am trying to get bluetooth discovery results through an apk which runs as android junit runner. Everything works fine but while registerReciever I get below error. What could

2条回答
  •  自闭症患者
    2021-01-23 10:15

    I have found answer myself. Using InstrumentationRegistry.getTargetContext() solved my problem.

    InstrumentationRegistry.getInstrumentation(), returns the Instrumentation currently running.

    InstrumentationRegistry.getContext(), returns the Context of this Instrumentation’s package.

    InstrumentationRegistry.getTargetContext(), returns the application Context of the target application.

    Here are some info- https://developer.android.com/reference/android/support/test/InstrumentationRegistry.html#getTargetContext()

    But still I am not sure when to use InstrumentationRegistry.getContext()...

提交回复
热议问题