flutter - Flutter 如何解决找不到具有权限的提供者的元数据以及与 FileProvider 的其他插件冲突的问题?
问题描述
实际上我正在使用open_file
和flutter_webview_plugin packages
在同一个项目中。运行应用程序时出现如下错误:-
java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.example.fileprovider
然后我找到了一个文档来添加提供者来解决这个问题,所以我添加了Androidmanifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example">
...
<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/provider_paths"
tools:replace="android:resource" />
</provider>
</application>
添加此提供程序后,也会出现相同的错误。在这两个包中,他们都使用 fileProvider。因此,它正在发生冲突。
所以,帮我配置两个包fileProvider。
dependencies:
open_file: ^3.0.1
flutter_webview_plugin: ^0.3.11
提前致谢。
解决方案
是的,经过一整天的冲浪,我已经解决了这个问题,使用自定义文件提供程序来避免与其他插件发生冲突,例如open_file
.
请按照flutter_webview_plugin
以下步骤解决它。
步骤1
在android/src/main/AndroidManifest.xml
消除
android:name="androidx.core.content.FileProvider"
添加
android:name="com.flutter_webview_plugin.FlutterWebviewPluginFileProvider"
第2步
在android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPluginFileProvider.java
创建新班级FlutterWebviewPluginFileProvider.java
package com.flutter_webview_plugin;
import androidx.core.content.FileProvider;
public class FlutterWebviewPluginFileProvider extends FileProvider {
}
步骤:3
在android/src/main/java/com/flutter_webview_plugin/WebviewManager.java
删除导入
import androidx.core.content.FileProvider;
查找并删除此行
return FileProvider.getUriForFile(context, packageName + ".fileprovider", capturedFile);
添加这个
return FlutterWebviewPluginFileProvider.getUriForFile(context, packageName + ".fileprovider", capturedFile);
Refered by :
https://github.com/fluttercommunity/flutter_webview_plugin/commit/aeda1e80effd59afdb526b11608cb232a83a6bab
谢谢
推荐阅读
- python - 列表对象的python变量名,最佳实践
- r - R:按数据集分组,条件是组中特定列中的所有值都符合某些要求
- r - 如何在 R 中按中位数或众数填充 NA
- nginx - 为什么浏览器在响应 413 的情况下显示 CORS 错误?
- google-bigquery - 用于扩展 json 以记录的 BigQuery UDF
- javascript - 从对象的数据数组中填充视图 Angular
- r - R中删除的小数位
- google-apps-script - Google App Script 读取特定文件夹中的文件
- c - fscanf 上的分段错误
- java - 为什么 addNode() 方法返回编译错误“方法...类型...不适用于参数...”,我该如何解决?