We are getting some issue in the prod as below and It only observed to a few devices in the prod. I believe we don't need to give any read write or read image permission to access any storage framework. Does anyone know what would be the issue ?
Android 12- Non-fatal Exception: java.lang.IllegalStateExcetion: Only owner is able to interact with pending/trashed item content://media/external_primary_images/Media Android 10/9 - Non-fatal exception: java.io.FileNotFoundException: open failed: ENOENT
@Composable
fun HomeScreenNavigationEntry() {
val context = LocalContext.current
val filePickerLauncher = rememberFilePickerLauncher(context) { intent ->
Toast.makeText(context, "File received!!", Toast.LENGTH_SHORT).show()
}
HomeScreen(
fileLauncher = {
val intent = filePickerIntent()
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
filePickerLauncher.launch( filePickerIntent())
}
)
}
@Composable
fun rememberFilePickerLauncher(context: Context,
onRememberFilePickerLauncherResult: (intent: Intent?) -> Unit,
): ManagedActivityResultLauncher<Intent, ActivityResult> {
return rememberLauncherForActivityResult(contract = ActivityResultContracts.StartActivityForResult()){ activityResult ->
if (activityResult.resultCode == Activity.RESULT_OK) {
onRememberFilePickerLauncherResult(activityResult.data, context)
} else {
onRememberFilePickerLauncherResult(null)
}
}
}
private fun filePickerIntent(): Intent {
val fileType = "application/pdf"
val mimeTypes = arrayOf(fileType)
return Intent(Intent.ACTION_OPEN_DOCUMENT)
.addCategory(Intent.CATEGORY_OPENABLE)
.setType("*/*")
.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)
}
fun onRememberFilePickerLauncherResult(intent: Intent?, context: Context) {
val uri = intent?.data ?: return
val flag = Intent.FLAG_GRANT_READ_URI_PERMISSION
val contentResolver = context.contentResolver
contentResolver.takePersistableUriPermission(uri, flag)
processUri(uri)
}
trying to access below line and getting crash:(Fatal Exception: java/lang.SecurityException: PErmission Denial: Opening provider com.android.providers.downloads.DownloadStorageProvider from processRecord(URI) requires that you obtain access using ACTION_OPEN_DOCUMENT or relate)
fun processUri(uri: Uri) {
Cursor cursor = contenrResolver.query(uri, null, null, null)
}
All code is written in a single activity.