Android:自动选择调试/发布 Maps api key ?

标签 android google-maps debugging key android-mapview

已过时:这个老问题是指已过时的 Google Maps v1 API。使用v2 API时,可以在一个中使用多个证书指纹Google API Console入口。 API Key 不再存储在 Manifest 或代码中。


是否可以自动检测用于签署 APK 的证书?我想在应用程序中同时调试和发布 map 证书,并将有效的证书传递给 MapView 构造函数。

通过这样的设置,我在发布应用程序时不会出错 - 我在模拟器和我的设备上使用调试证书,然后在将应用程序发送到 Market 之前使用发布版本签名。

我正在考虑检测我的特定设备或调试器是否已连接,但它并不完美。也许调试证书需要一些文件标记?有没有更好的办法?

最佳答案

SDK Tools, Revision 17 中有一种新方法可以确定是调试版本还是发布版本.新功能概述的摘录:

Builds now generate a class called BuildConfig containing a DEBUG constant that is automatically set according to your build type. You can check the (BuildConfig.DEBUG) constant in your code to run debug-only functions.

所以现在你可以简单地写这样的东西:

if (BuildConfig.DEBUG)
{
    //Your debug code goes here
}
else
{
    //Your release code goes here
}

更新:我在 ADT 中遇到了错误:有时 BuildConfig.DEBUG 在导出应用程序包后为 true。说明在这里:http://code.google.com/p/android/issues/detail?id=27940

关于Android:自动选择调试/发布 Maps api key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3029819/

相关文章:

asp.net - 如何将default.aspx设置为Visual Studio调试器的默认启动点?

java - 播放声音的非常简单的 ListPreference 不起作用。有任何想法吗? (大量细节)

javascript - 创建类似于 Google Analytics 的分析 map

php - 边栏 Google Maps API v3 使用 PHP/MYSQL 提取数据

php - 显示所有错误和警告

手动终止进程( Activity )后进行Android调试

android - 如何以编程方式实时读取logcat?

android - 无法替换android studio中的默认图标

android - 如何处理android中搜索 View 的后退按钮

swift - 如何在 Google Place AutocompleteViewController 的 GMSAutocompleteViewController 中设置文本