0

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.

Ergi16
  • 13
  • 2
  • There is no "real path". Use the `Uri` properly. See the answer on the duplicate question for three links to resources for how to do this. – CommonsWare May 19 '23 at 14:59
  • This is not the case , I get wrong the uri since when I get intentResult result.data?.data? I get fileName wrong I get a strange number this ->content://com.android.providers.media.documents/document/document%3A1000000089 Instead I should have received like that -> content://com.android.providers.media.documents/document/document%fileName.fileType And this happens only with android 13 – Ergi16 May 19 '23 at 20:37
  • There is no requirement for `ACTION_GET_CONTENT` to return a `Uri` of any particular structure, and there is no requirement for a `Uri` to point to something on the filesystem that you can access via a filesystem path. There are tens of thousands of Android device models; you have tested on a very tiny percentage of those. Please use the `Uri` properly. – CommonsWare May 19 '23 at 23:25

0 Answers0