I\'m using espresso for testing but sometimes I try to get an image form external storage and with marshmallow I need a Runtime permission otherwise there will be an Excepti
You can grant and revoke permissions using:
adb shell pm grant com.package.myapp android.permission.
adb shell pm revoke com.package.myapp android.permission.
To use from Java instrumentation tests call this method from Google samples: https://github.com/googlesamples/android-testing/blob/ed62c450e43f859333b3113d44dd59f75971b529/ui/espresso/IntentsBasicSample/app/src/androidTest/java/com/example/android/testing/espresso/BasicSample/DialerActivityTest.java#L94