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"
            }
        }
    }
}

按说明配置问题解决了。

相关推荐
夜雨声烦丿3 小时前
Flutter 框架跨平台鸿蒙开发 - 中英互译助手 - 完整开发教程
flutter·华为·harmonyos
一个小废渣4 小时前
Flutter Web端网络请求跨域错误解决方法
前端·flutter
鸣弦artha5 小时前
Flutter框架跨平台鸿蒙开发——Extension扩展方法
android·javascript·flutter
小白阿龙5 小时前
鸿蒙+flutter 跨平台开发——图像编解码与水印嵌入技术实战
flutter·华为·harmonyos·鸿蒙
夜雨声烦丿5 小时前
Flutter 框架跨平台鸿蒙开发 - 成语词典 - 完整开发教程
flutter·华为·harmonyos
[H*]6 小时前
Flutter框架跨平台鸿蒙开发——MethodChannel方法通道
flutter
kirk_wang6 小时前
Flutter艺术探索-Flutter网络请求基础:http包使用指南
flutter·移动开发·flutter教程·移动开发教程
小白阿龙6 小时前
鸿蒙+flutter 跨平台开发——基于日历视图的生理周期计算逻辑
flutter·华为·harmonyos·鸿蒙
kirk_wang7 小时前
Flutter艺术探索-Flutter包管理:pubspec.yaml配置详解
flutter·移动开发·flutter教程·移动开发教程
猛扇赵四那边好嘴.7 小时前
Flutter 框架跨平台鸿蒙开发 - 脑筋急转弯应用开发教程
flutter·华为·harmonyos