Flutter:open_file打开本地文件报错问题

相关插件及版本: open_file: ^3.2.1

问题:

项目中一直用的这个插件,突然发现在安卓高版本不能正常使用,报权限问题permissionDenied,断点调试提示相关权限是MANAGE_EXTERNAL_STORAGE,申请权限之后还是不行,报错内容是Failed to find configured root that contains ,如下

bash 复制代码
java.lang.RuntimeException: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/包名/flutter_app/测试.pdf

open_file插件地址

按说明重新配置filepaths依旧不行,找到了open_file的升级版open_filex

To use this plugin, add open_filex as a dependency in your pubspec.yaml file.

bash 复制代码
dependencies:
  open_filex: ^lastVersion

Example

bash 复制代码
import 'package:open_filex/open_filex.dart';

OpenFilex.open("/sdcard/example.txt");

when Conflict with other plugins about FileProvider, add code below in your /android/app/src/main/AndroidManifest.xml

bash 复制代码
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="xxx.xxx.xxxxx">
    <application>
        ...
        <provider
                android:name="androidx.core.content.FileProvider"
                android:authorities="${applicationId}.fileProvider"
                android:exported="false"
                android:grantUriPermissions="true"
                tools:replace="android:authorities">
            <meta-data
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/filepaths"
                    tools:replace="android:resource" />
        </provider>
    </application>
</manifest>

furthermore add code below in your /android/app/src/main/res/xml/filepaths.xml

bash 复制代码
<paths>
    <external-path name="external-path" path="."/>
    <external-cache-path name="external-cache-path" path="."/>
    <external-files-path name="external-files-path" path="."/>
    <files-path name="files_path" path="."/>
    <cache-path name="cache-path" path="."/>
    <root-path name="root" path="."/>
</paths>

when Android dependency 'com.android.support:appcompat-v7' has different version for the compile error, add code below in your /android/build.gradle

bash 复制代码
subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.1.1"
            }
        }
    }
}

按说明配置问题解决了。

相关推荐
yeziyfx2 小时前
Flutter 宽度充满屏幕的按钮
flutter
里欧跑得慢3 小时前
Flutter 组件 tavily_dart 的适配 鸿蒙Harmony 实战 - 驾驭 AI 搜索引擎集成、实现鸿蒙端互联网知识精密获取与语义增强方案
flutter·harmonyos·鸿蒙·openharmony·tavily_dart
国医中兴4 小时前
Flutter 三方库 pickled_cucumber 的鸿蒙化适配指南 - 玩转 BDD 行为驱动开发、Gherkin 自动化测试实战、鸿蒙级质量守护神
驱动开发·flutter·harmonyos
里欧跑得慢4 小时前
Flutter 三方库 config 的鸿蒙化适配指南 - 在鸿蒙系统上构建极致、透明、多源叠加的命令行参数解析与环境配置文件加载引擎
flutter·harmonyos·鸿蒙·openharmony
左手厨刀右手茼蒿4 小时前
Flutter 三方库 flutter_azure_tts 深度链接鸿蒙全场景智慧语音中枢适配实录:强势加载云端高拟真情感发音合成系统实现零延迟超自然多端协同-适配鸿蒙 HarmonyOS ohos
flutter·harmonyos·azure
雷帝木木4 小时前
Flutter 三方库 image_compare_2 的鸿蒙化适配指南 - 实现像素级的图像分块对比、支持感知哈希(pHash)与端侧视觉差异检测实战
flutter·harmonyos·鸿蒙·openharmony·image_compare_2
王码码20354 小时前
Flutter 三方库 sum_types 的鸿蒙化适配指南 - 引入函数式编程思维,让鸿蒙应用的状态处理更严谨
flutter·harmonyos·鸿蒙·openharmony·sum_types
加农炮手Jinx4 小时前
Flutter 三方库 cli_script 鸿蒙化极简命令行执行引擎适配探索:在多维沙盒终端环境注入异构 Shell 串联逻辑彻底拔高全自动化容器脚本运维及-适配鸿蒙 HarmonyOS ohos
运维·flutter·harmonyos
王码码20354 小时前
Flutter 三方库 simple_rsa 的鸿蒙化适配指南 - 实现非线性 RSA 密钥对生成与端侧文本加解密、支持标准公钥指纹验证与高强度数字签名实战
flutter·harmonyos·鸿蒙·openharmony·simple_rsa