I've been trying to build an app that is able to recover a photo from the gallery and use it in a recycler view with some content information previously registered. I'm able to recover this photo normally, set it into the recycler view but when I close the app and open again, I receive the message saying that I don't have permission to access this content.
java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{d5d38d1 7118:com.tods.docreminder/u0a169} (pid=7118, uid=10169) requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
This is the way that I'm recovering the image from the gallery:
private fun configExternalStorageIntent(pathGallery: Int) {
val intent = Intent()
intent.type = "image/*"
intent.action = Intent.ACTION_OPEN_DOCUMENT
startActivityForResult(Intent.createChooser(intent, "Select: "), pathGallery)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(resultCode == RESULT_OK) {
val selectedImage = data.data
try {
when (requestCode) {
content...
}
imageList.add(selectedImage.toString())
} catch (e: Exception){
e.printStackTrace()
}
}
}
And that is my manifest permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera"/>
<queries>
<intent>
<action android:name="android.intent.action.VIEW"/>
</intent>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE"/>
</intent>
</queries>
I'm saving the uri from the selected image and displaying it on another fragment. I register it on Fragment 2 and displays it on Fragment 1. I'm able to display it normally in the first time, but it crashes when I open the app again. This list is saved in room database. Any suggestions?
Thanks in advance. If is there any information missing just tell me and I update it.