On Android 13 I have an issue while trying to get uri from Intent . I have txt and cs file and send intent like this :
private fun performFileSearch() {
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
val mimeTypes = arrayOf("text/csv", "text/*")
intent.type = "*/*"
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)
resultLauncher.launch(intent)
}
Then when I get the intent :
private var resultLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
// There are no request codes
val realPath = result.data?.data?.let {
it.path?.let { it1 -> Log.d("Here is path from data ", it1) }
PathUtils.getReadablePathFromUri(
requireContext(),
it
)
}
}
}
But when I get this uri is something like this content://com.android.providers.media.documents/document/document%3A1000000089 while I am expecting that content://com.android.providers.media.documents/document/document%fileName
So the problem that I have is that when I convert this on multipart the file name is null because I do sth like this val file = File(realPath)
When I try with different versions of real devices for example android 10 or 12 it is ok ,in emulator is everything ok but with Android 13 this issue is happening.