简体   繁体   中英

How do you get access to a testing device's files when running instrumentation tests for Android

I have set up a physical device with files that can be retrieved through the MediaStore. My goal is to retrieve these files through the MediaStore in an instrumented test.

Currently, when I push the debug app to the device and test it manually, the device files are found. The problem is when I am running instrumentation tests, and I get nothing from the MediaStore.

Is there a way to get the files through the MediaStore in an instrumentation test?

Possible relevant: I define and use a dummy Activity in my instrumentation test class

        Looper.prepare()
        dummyActivity = DummyActivity()

I then tried to define the dummy Activity in the debug folder, declare it in the debug manifest, and instantiate it via an ActivityScenario. Didn't help.

I made the assumption that manifest permissions carried over to test package from the debug package. Not so.

Adding the following line to my test class made the MediaStore query return the files on the device!

    @get:Rule
    var mRuntimePermissionRule = GrantPermissionRule.grant(Manifest.permission.READ_EXTERNAL_STORAGE)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM