Flutter 找不到具有权限的提供者的元数据 [英] Flutter Couldn't find meta-data for provider with authority
问题描述
我有一个使用 flutter_webview_plugin 0.3.8
的应用.我在 webview 中打开一个网页并显示其内容.页面中有一个按钮,当您按下它时,它应该会像在 chrome 等普通网络浏览器中一样打开一个文件浏览器.该按钮在 chrome 中工作正常,它会打开一个底部小部件来选择一个动作(相机、文件、……).但是在我的 webview 中,它崩溃并显示错误 Couldn't find meta-data for provider with authority com.example.booshehr.fileprovider
.完整的错误是:
I have an app that is using flutter_webview_plugin 0.3.8
. I open a webpage in webview and show its content. There is a button in the page and when you press it, it should open a file explorer like it does in normal web browser like chrome.The button works fine in chrome and it opens a bottom widget to choose an action ( camera, files , ...). But in my webview it crashes with the error Couldn't find meta-data for provider with authority com.example.booshehr.fileprovider
. The full error is :
W/System.err(15213): java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.example.booshehr.fileprovider
W/System.err(15213): at androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:606)
W/System.err(15213): at androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:579)
W/System.err(15213): at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:417)
W/System.err(15213): at com.flutter_webview_plugin.WebviewManager.getOutputFilename(WebviewManager.java:272)
W/System.err(15213): at com.flutter_webview_plugin.WebviewManager.access$800(WebviewManager.java:42)
W/System.err(15213): at com.flutter_webview_plugin.WebviewManager$3.onShowFileChooser(WebviewManager.java:211)
W/System.err(15213): at In.a(PG:145)
W/System.err(15213): at uE0.runFileChooser(PG:2)
W/System.err(15213): at android.os.MessageQueue.nativePollOnce(Native Method)
W/System.err(15213): at android.os.MessageQueue.next(MessageQueue.java:325)
W/System.err(15213): at android.os.Looper.loop(Looper.java:142)
W/System.err(15213): at android.app.ActivityThread.main(ActivityThread.java:6710)
W/System.err(15213): at java.lang.reflect.Method.invoke(Native Method)
W/System.err(15213): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
W/System.err(15213): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
F/chromium(15213): [FATAL:jni_android.cc(249)] Please include Java exception stack in crash report
F/libc (15213): Fatal signal 5 (SIGTRAP), code 1 in tid 15213 (xample.booshehr)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'lge/elsa_global_com/elsa:8.0.0/OPR1.170623.032/18325232422a1:user/release-keys'
Revision: '12'
ABI: 'arm64'
pid: 15213, tid: 15213, name: xample.booshehr >>> com.example.booshehr <<<
signal 5 (SIGTRAP), code 1 (TRAP_BRKPT), fault addr 0x714216eb04
x0 0000000000000000 x1 0000000000000081 x2 000000007fffffff x3 0000000000000000
x4 0000000000000000 x5 0000000000000000 x6 0000000000000000 x7 7f7f7f7f7fffff7f
x8 0000000000000000 x9 0000000000000000 x10 0000000000000001 x11 0000000000000000
x12 0000007134d6ff00 x13 0000000000000000 x14 0000000000000000 x15 000000716228c000
x16 000000715dfd2208 x17 000000715df25c50 x18 000000006fba3d30 x19 0000007fd17f5c70
x20 0000007fd17f5c78 x21 0000007fd17f5c80 x22 000000000000004f x23 000000715dfd4808
x24 0000007143e3f000 x25 0000007fd17f5e70 x26 0000000000000001 x27 0000007162612a48
x28 0000007162612a48 x29 0000007fd17f5c60 x30 000000714216e9c4
sp 0000007fd17f57b0 pc 000000714216eb04 pstate 0000000060000000
backtrace:
#00 pc 0000000001e9fb04 /data/app/com.android.chrome-HU8bsIOJpUMqks882ELhSA==/base.apk (offset 0xc19000)
#01 pc 0000000001e9f9c0 /data/app/com.android.chrome-HU8bsIOJpUMqks882ELhSA==/base.apk (offset 0xc19000)
我已经尝试将 provider
添加到 androidmanifest,仍然是同样的错误:
I have tried adding provider
to androidmanifest, still the same error:
<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>
我的 @xml/filepaths
是:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path name="myapp" path="images/"/>
</paths>
然后我尝试将 android:authorities="${applicationId}.fileProvider"
更改为 android:authorities="${applicationId}.myOwnFileProvider"
,仍然是同样的错误.
Then I tried changing the android:authorities="${applicationId}.fileProvider"
to android:authorities="${applicationId}.myOwnFileProvider"
, still the same error.
请帮我解决这个问题.
推荐答案
从抛出的日志来看,它看起来像是使用 Intent 启动 Android 应用程序.WebView 中显示的按钮的功能是什么?您可以使用 android_intent 插件通过 Intent 在 Android 上启动应用,即
Base from the logs being thrown, it looks like an Android app is being launched using an intent. What's the function on the button displayed inside the WebView? You can use android_intent plugin for launching apps on Android via intent i.e.
if (Platform.isAndroid) {
final AndroidIntent intent = AndroidIntent(
action: 'action_view', // Update with the required action flag
data: 'package:com.example.booshehr.fileprovider',
);
await intent.launch();
}
此问题的另一个可能原因是您可能使用的插件尚不支持您正在运行的平台.
Another possible cause of this issue is that you might be using a plugin that has yet to support the platform that you're running on.
这篇关于Flutter 找不到具有权限的提供者的元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!