I am trying to upload a file from my device to my android app using the below code.
Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
type = "*/*"
putExtra(Intent.EXTRA_MIME_TYPES, arrayOf(
"image/*",
"application/pdf", // .pdf
"application/vnd.oasis.opendocument.text"
))
},
1
)
}
OnActivityResult code:
if (requestCode == 1) {
val fileName = findViewById<TextView>(R.id.fileName)
val file = File(data?.data?.path)
Log.d("TAG", "Uri:: ${data?.data.toString()} ${file.absoluteFile}")
}
When using Emulator to test the upload , the file name is correctly reflected but when testing through a device (Android 8 and above) , the file name and file Uri are not correct.
**The URI: content://com.android.providers.media.docuemtns/document/image%A33
and FILE NAME: /document/image:33 are shown.**
I have tried both ACTION_OPEN_DOCUMENT and ACTION_GET_CONTENT actions with no success. Any suggestions or help will be greatly appreciated.
The URI and File name has to be correct.