繁体   English   中英

url_launcher 更新后如何启动谷歌地图 uri?

[英]How to launch google maps uri after url_launcher update?

我已经将我的 flutter 应用程序包包括url_launcher package 从6.0.20更新到6.1.2

更新后,许多 Android 用户(API 30/31/32)报告由于错误,他们无法使用 Google 地图应用程序启动导航到定义的点(纬度和经度):

Webpage not available. 

Webpage not available
The webpage at intent://maps.app.goo.gl/?
link=https://www.google.com/maps/dir//45.8597077,.........
could not be loaded because:
net: ERR_UNKNOWN_URL_SCHEME

这是我使用6.0.20的工作代码

final String gMapsUrl = 'https://www.google.com/maps/dir/api=1&destination=$latitude,$longitude&travelmode=driving';

if (Platform.isAndroid && await canLaunch(gMapsUrl)) {
  await launch(gMapsUrl);
}

这是与6.1.2不兼容的

 final String gMapsUrl = 'https://www.google.com/maps/dir/api=1&destination=$latitude,$longitude&travelmode=driving';

if (Platform.isAndroid && await canLaunchUrl(gMapsUri)) {
  await launchUrl(gMapsUri);
} 

现在哪个是启动谷歌地图 url 以启动 inApp 或 web 浏览器导航而不强制用户使用 inApp 或 Web 导航的正确方法?

[✓] Flutter (Channel stable, 2.10.3, on macOS 12.4 21F79 darwin-x64, locale en-IT)
    • Flutter version 2.10.3 at /Users/enrico/SDKs/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (3 months ago), 2022-03-02 11:23:12 -0600
    • Engine revision bd539267b4
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/enrico/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)

[✓] VS Code (version 1.67.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (2 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 12 (API 32) (emulator)
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 101.0.4951.64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

声明应用程序要打开 URL。

<!-- Place inside the <queries> element. -->
<intent>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data android:scheme="https" />
</intent>

可能在这两个版本之间更改了一些默认值。 现在指定mode我解决了强制打开应用程序的问题:

await launchUrl(gMapsUri, mode: LaunchMode.externalApplication);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM