SAF:找不到处理意图的活动 - android.intent.action.OPEN_DOCUMENT_TREE - Android 13

问题描述 投票:0回答:1

刚刚更新了应用程序,该应用程序现在仅适用于 SAF,因此用户可以选择他们想要的任何目录,并且应用程序不仅可以使用媒体文件(MediaStore 是一个无用的东西)。

但我在 Firebase Crashlytics 中得到了有趣的东西:

致命异常:android.content.ActivityNotFoundException 没有活动 发现处理 Intent { act=android.intent.action.OPEN_DOCUMENT_TREE (有额外内容)}

适用于运行 Android 13 的 Galaxy A52 设备

没想到竟然会缺少这样的东西,尤其是在Android 13设备上。

我该如何处理此类错误?我什至可以帮助用户解决此类问题,mb 建议他们从 Goolge Play 安装文件浏览器应用程序之一,为我的应用程序选择带有

android.intent.action.OPEN_DOCUMENT_TREE
的目录是否有帮助?

fun selectFolderSaf(
    activity: Activity,
    coroutineScope: CoroutineScope,
    activityResultLauncher: ActivityResultLauncher<Intent>,
) {
    val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        val storageManager =
            activity.getSystemService(Context.STORAGE_SERVICE) as StorageManager
        storageManager.primaryStorageVolume.createOpenDocumentTreeIntent()
    } else {
        Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
    }

    with(intent) {
        putExtra("android.content.extra.SHOW_ADVANCED", true)
        putExtra("android.content.extra.FANCY", true)
        putExtra("android.content.extra.SHOW_FILESIZE", true)
    }
    coroutineScope.launch {
        activityResultLauncher.launch(intent)
    }
}
android android-intent storage-access-framework android-storage
1个回答
0
投票

没想到竟然会缺少这样的东西,尤其是在Android 13设备上。

那些

Intent
操作并不总是受支持,尤其是在非典型外形尺寸上。例如,Android TV 和 Wear OS 都不可靠地支持它们。

适用于运行 Android 13 的 Galaxy A52 设备

从技术上讲,对于 Android 13,您的代码并不是直接使用

ACTION_OPEN_DOCUMENT_TREE
。您正在使用
storageManager.primaryStorageVolume.createOpenDocumentTreeIntent()
的结果。三星可能没有充分测试其 Android 集成的这一特定部分。

我该如何处理此类错误?

如果

ACTION_OPEN_DOCUMENT_TREE

 启动抛出 
storageManager.primaryStorageVolume.createOpenDocumentTreeIntent()
,则
回退到普通
ActivityNotFoundException
请求。

如果也失败,请说“抱歉,您的设备不兼容”。

我可以帮助用户解决这些问题吗

一般不会。

mb 建议他们从 Goolge Play 安装文件浏览器应用程序之一,为我的应用程序选择带有 android.intent.action.OPEN_DOCUMENT_TREE 的目录是否有帮助?

没有。

© www.soinside.com 2019 - 2024. All rights reserved.