清单文件中的多个 Google api 密钥(Android) [英] Multiple Google api keys in manifest file (Android)

查看:24
本文介绍了清单文件中的多个 Google api 密钥(Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加两个 api 密钥,即 Google 放置 api 密钥和 google maps api 密钥.但是我无法同时将两者添加到清单文件中.我怎样才能实现相同的目标.任何帮助将不胜感激.提前致谢.

I am trying to add two api keys i.e Google places api key and google maps api key. But I am not able to add both at same time to manifest file.How can I achieve the same.Any help would be appreciated. Thanks in advance.

我得到的错误是

Caused by: java.lang.RuntimeException: API key 只能指定一次.建议您在AndroidManifest.xml 元素中使用名称为:com.google.android.geo.API_KEY 的元数据标签

Caused by: java.lang.RuntimeException: The API key can only be specified once. It is recommended that you use the meta-data tag with the name: com.google.android.geo.API_KEY in the element of AndroidManifest.xml

我包含这样的 api 密钥

I am including api keys like this

 <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="xxxxx" />

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="xxxx"/>

推荐答案

在清单中使用以下元数据.如果您已经有谷歌地图的 api 密钥,则无需为地点 api 创建另一个 api 密钥.如果您同时使用 Maps &Places Api 在您的应用程序中,然后您只需要指定 geo api 密钥.只需启用 Places Api.

Use following meta-data in your manifest. there is no need to create another api key for places api if you already have api key for google map. If you are using both Maps & Places Api in your application then you only need to specify geo api key.and just enable Places Api.

<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="api_key" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

这篇关于清单文件中的多个 Google api 密钥(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆