Storage access frame in test application

I use Intent.ACTION_OPEN_DOCUMENT_TREE to give my application the ability to write to external storage (on Lollipop and Marshmallow).

But I would like to write external storage in a test application. Intent.ACTION_OPEN_DOCUMENT_TREE uses the system dialog, so I cannot provide permission during the tests. I also tried to resolve it in the application and then use it in tests, but it is not shared - the application project and the test project are different packages.

Does anyone know of a workaround that can, for example, provide permission for all external storage for testing purposes? Maybe by changing some kind of system property?

adb shell setprop SOMEPROPERTY 1

+8
android testing android-externalstorage storage-access-framework
source share
2 answers

You can try these commands to grant and revoke permissions.

 adb pm grant com.package.myapp android.permission.<PERMISSION> adb pm revoke com.package.myapp android.permission.<PERMISSION> 

Read / Write Permissions for External Storage

 android.permission.WRITE_EXTERNAL_STORAGE android.permission.READ_EXTERNAL_STORAGE 

Here's a link to the video that explains: Runtime permissions in Android 6.0 Marshmallow (Android Ep 3 development templates) .

+1
source share

As a workaround, you can use the adb shell input keyevent flag to check the access permission flag.

Using:

  adb shell input [text|keyevent] adb shell input text <string> adb shell input keyevent <event_code> 

You can find more information here.

0
source share

All Articles