我的 Android 应用程序打开“文档树”选择器以提示对外部存储完整目录的读取权限(根据 Android 10+ 范围存储规则)。
相关代码
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
startActivityForResult(intent, REQUEST_ID_PERMISSION);
适用于所有经过测试的版本和设备变体。 但是,我的崩溃显示以下错误在某些三星设备上多次发生。 (A20 - Android 9 | S10/10+ - Android 10 和 11 | Note20 - Android 11)
Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT_TREE flg=0x40 }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2071)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1717)
at android.app.Activity.startActivityForResult(Activity.java:5252)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
此问题的任何潜在原因和解决方案,请了解:
谢谢你。