0

I have written a functionality in Kotlin for the flutter app to share media files directly from the android phone gallery to the app.
Working fine for many devices I have tested like Realme 3 Pro, Oneplus 6t, Samsung m40.
But, for Asus Zenfone Max Pro M2 on sharing any media file received weird and incomplete URI & path
Logs from Kotlin Code

D/URI
=====(26032) : content://com.android.providers.downloads.documents/document/624

D/Path =====(26032): /document/624

Kotlin Code
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
this.binding = binding
binding.addOnNewIntentListener(this)
handleIntent(binding.activity.intent, true)
}
———————————————————————-
private fun handleIntent(intent: Intent, initial: Boolean) {
when {
(intent.type?.startsWith(“text”) != true)
&& (intent.action == Intent.ACTION_SEND
|| intent.action == Intent.ACTION_SEND_MULTIPLE) -> { // Sharing images or videos

val value = getMediaUris(intent)
if (initial) initialMedia = value
latestMedia = value
eventSinkMedia?.success(latestMedia?.toString())
}

———————————————————————-
private fun getMediaUris(intent: Intent?): JSONArray? {
if (intent == null) return null

return when (intent.action) {
Intent.ACTION_SEND -> {
val uri = intent.getParcelableExtra(Intent.EXTRA_STREAM)
Log.d(“URI =====”,uri)
val path = uri?.let{ FileDirectory.getPathFromUri(applicationContext, it) } ?: uri?.path
Log.d(“Path =====”,path)
if (path != null) {

Device Info
Device Name: Asus Zenfone Max Pro M2
Android Version: 9
External SD card: present

How to resolve this URI and get a proper path with filename and extension?