【问题标题】:How to add Android intent to open google maps in Cordova/Ionic project?如何添加 Android 意图以在 Cordova/Ionic 项目中打开谷歌地图?
【发布时间】:2021-12-27 00:33:28
【问题描述】:

Android API 30 (Android 11) 需要在应用清单中定义的额外权限才能打开其他应用(在我的例子中是 Google 地图)。但是,如果 <manifest> 元素在 Ionic/Cordova 项目中不可用,我如何才能在我的项目中获得此权限?我有一个config.xml 文件,其中列出了 Android 和 iOS 的权限,但我不知道在哪里添加此权限。

Others 表示此 API 更改需要在 <manifest> 中添加权限

在我的 Ionic 5 项目中,我只能编辑如下所示的 config.xml 文件:

    <platform name="android">
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
            <application android:networkSecurityConfig="@xml/network_security_config" />
            <queries>
                <package android:name="com.google.android.apps.maps" />
            </queries>
        </edit-config>
        <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
        <allow-intent href="market:*" />

我已尝试添加建议的 &lt;queries&gt; 元素,但这不起作用。我单击 UI 中的地址并使用 Ionic Launch Navigator 插件打开 Google 地图。它适用于 Android API 29,但不适用于 API 30。

我应该如何添加在Android中打开谷歌地图的权限?

【问题讨论】:

    标签: android cordova ionic-framework android-11


    【解决方案1】:

    window.open(URL) 可在 Android 11 上运行,无需更改权限或 API 密钥即可打开 Google 地图。 See help article.

    文章解释了如何构建URL以跨平台的方式打开谷歌地图,支持查找位置和导航。我不必弄乱权限或 AndroidManifest.xml 或 Cordova 元素。

    在挖掘过程中,我使用了 Ionic 建议的 Launch Navigator 插件,该插件打开 Google 地图的方式略有不同,并且由于 Android 11 权限更改,此插件现在需要 Intent 权限,我无法弄清楚并放弃了启动 -网址格式。

    【讨论】:

      猜你喜欢
      • 2017-08-17
      • 1970-01-01
      • 1970-01-01
      • 2018-01-02
      • 1970-01-01
      • 1970-01-01
      • 2011-07-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多