My activity needs to request a new document from a document provider.
I want to test this in my espresso test by intenting an activity result with a uri. However, the returned uri does not have the correct permissions granted. At least I get a SecurityException: No persistable permission grants found for [user] and [uri]
when I try to takePersistableUriPermission
The relevant code of my activity in onActivityResult:
val takeFlags = data.getFlags() and (Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
contentResolver.takePersistableUriPermission(it, takeFlags)
The relevant code for the espresso test
val file = File(InstrumentationRegistry.getTargetContext().filesDir, "abc.txt2)
val uri = Uri.parse("file://" + file.absoluteFile)
Intents.intending(hasAction(Intent.ACTION_CREATE_DOCUMENT))
.respondWith(Instrumentation.ActivityResult(RESULT_OK, Intent().setData(uri)))
<click on button to request document>
How to intenting an activity result with a uri that comes with granted permissions?