Flutter url_launcher plugin throws "java.lang.IllegalArgumentException: Receiver not registered: io.flutter.plugins.urllauncher.WebViewActivity"

huangapple go评论69阅读模式
英文:

Flutter url_launcher plugin throws "java.lang.IllegalArgumentException: Receiver not registered: io.flutter.plugins.urllauncher.WebViewActivity"

问题

I'm attempting to use Flutter's url_launcher plugin to open webpages.

当我点击按钮时,url_launcher成功打开了一个网页。但是,如果我然后向左滑动返回,或者使用软件返回按钮,应用程序会崩溃。日志显示

> java.lang.RuntimeException: Unable to destroy activity
> {uk.co.pottertour.map_edinburgh_guide_airbnb/io.flutter.plugins.urllauncher.WebViewActivity}:
> java.lang.IllegalArgumentException: Receiver not registered:
> io.flutter.plugins.urllauncher.WebViewActivity$1@8152196

它说是 WebViewActivity,所以 Url_Launcher 似乎不是打开外部浏览器,而是打开内置 WebView。

这相当关键,这个应用程序基本上是一个激动人心的事物的中心。

我怀疑我的 didChangeAppLifecycleState 函数是引发错误的原因,因为它发生在恢复时,但实际上是当 Flutter 运行构建并重新构建屏幕时。

我已经尝试注释掉包括 url_launcher 链接的构建过程的某些部分,认为重新构建会触发它,但这并没有帮助。也许有一些后台异步进程,在应用程序被绘制到屏幕之前引发了这个错误。与 url_launcher 有关。

英文:

I'm attempting to use Flutter's url_launcher plugin to open webpages.

When I click a button url_launcher opens a webpage successfully. However, if I then navigate back by swiping left, or using the soft back button, the app crashes. The logs say

> java.lang.RuntimeException: Unable to destroy activity
> {uk.co.pottertour.map_edinburgh_guide_airbnb/io.flutter.plugins.urllauncher.WebViewActivity}:
> java.lang.IllegalArgumentException: Receiver not registered:
> io.flutter.plugins.urllauncher.WebViewActivity$1@8152196

It says WebViewActivity so presumably Url_Launcher isn't opening an external browser but an in-app Webview.

This is pretty critical, this app is basically a hub for exciting things.

I was suspicious that my didChangeAppLifecycleState function was causing the error since it occurred on resume, but no, it's when Flutter runs build & rebuilds the screen.

I've tried commenting out parts of my build process that included url_launcher links, believing the rebuild triggered it, but this does not help. Perhaps there is some background asynchronous process, that throws this error before the app is painted to the screen. To do with url_launcher.

答案1

得分: 6

我遇到过与您相同的问题,如果您不想使用url_launcher进行应用内处理,我建议您使用以下解决方案:

Future<void> _launchUrl(Uri url) async {
  if (!await launchUrl(url, mode: LaunchMode.externalApplication)) {
    throw Exception('Could not launch $url');
  }
}

使用 mode: LaunchMode.externalApplication 选项,链接将在您的应用程序外部打开,当您返回到应用程序时不应该遇到任何问题。

英文:

I had your same problem and I suggest you this solution if you don't want an in-app handling with url_launcher (https://pub.dev/packages/url_launcher#browser-vs-in-app-handling):

Future&lt;void&gt; _launchUrl(Uri url) async {
  if (!await launchUrl(url, mode: LaunchMode.externalApplication)) {
    throw Exception(&#39;Could not launch $url&#39;);
  }
}

Using mode: LaunchMode.externalApplication the link will open outside your app and you shouldn't have any problems when you navigate back into your app.

答案2

得分: 3

这在 url_launched_android 6.0.34 中已修复。问题在 https://github.com/flutter/flutter/issues/127014 中进行了跟踪。

英文:

This is fixed in url_launched_android 6.0.34. The issue was tracked in https://github.com/flutter/flutter/issues/127014

答案3

得分: 2

"你现在可以通过以下方式覆盖依赖项:

dependency_overrides:
url_launcher_android: "<=6.0.32""

英文:

For now, you can override dependency with

dependency_overrides:
  url_launcher_android: &quot;&lt;=6.0.32&quot;

答案4

得分: 1

这已在 url_launched_android 版本号 6.0.34 中修复。

要升级传递依赖项,请在终端中使用以下命令:

flutter pub upgrade url_launcher_android

参考链接:https://github.com/flutter/flutter/issues/127014

英文:

This is fixed in url_launched_android Version No. 6.0.34.

To upgrade the transitive dependency use this command in the terminal:

flutter pub upgrade url_launcher_android

Refrence: https://github.com/flutter/flutter/issues/127014

huangapple
  • 本文由 发表于 2023年5月14日 02:05:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76244218.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定