2

Is it possible to specify multiple keys for Google Maps Android API in the same code base?

It looks like I have to change the key in manifest file each time I change keystore. It's not very convenient, imho, if you need to test the app signed with keys form debug and release keystores.

4

4 回答 4

3

我一次在清单中添加了两个键。像这样

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    ..
    android:versionCode="1"
    android:versionName="1.0" >

        <!-- RELEASE key -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="my-release-keu" />

        <!-- DEBUG key -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="my-debug-key" />

    </application>

</manifest>

显然,这行得通。看起来谷歌代码足够聪明,可以自动使用相关键。

于 2013-05-20T04:43:36.547 回答
2

我不认为这是你想要做的。您应该在 Google Developer API 控制台上将调试和发布 SHA1 密钥添加到 API 密钥。看看这个答案

于 2014-05-20T09:05:15.857 回答
0
String debugMapKey   = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String releaseMapKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

String mapKey = BuildConfig.DEBUG ? debugMapKey : releaseMapKey;

MapView mv = new MapView(this, mapKey);
于 2013-05-17T11:41:02.867 回答
0

AFAIK,没有这样做的程序形式。对于商品,您可以在 strings.xml 中定义 API 密钥,并从清单中检索它

于 2013-05-17T09:57:41.040 回答