我在 Kotlin 中为 flutter 应用程序编写了一个功能,可以将媒体文件直接从 Android 手机图库共享到应用程序。
在我测试过的许多设备上运行良好,例如 Realme 3 Pro、Oneplus 6t、三星 m40。
但是,在Asus Zenfone Max Pro M2共享任何媒体文件时,都会收到奇怪且不完整的信息URI&path
来自 Kotlin 代码的日志
D/URI =====(26032) : content://com.android.providers.downloads.documents/document/624
D/路径 =====(26032): /document/624
Kotlin 代码
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 …Run Code Online (Sandbox Code Playgroud)