English 中文(简体)
如何将Google Maps API密钥注入Android应用程序?
原标题:How to inject Google Maps API key into an Android application?

我在一个由几个开发人员组成的团队中工作。我们正在开发一个使用谷歌地图的Android应用程序。由于我们每个人都有不同的调试密钥库,所以每个人都拥有不同的API密钥。让每个开发人员(和构建服务器)在构建应用程序时自动将自己的密钥替换到应用程序中的最佳方式是什么?

最佳回答

我们使用了一个属性文件,将密钥存储在其中(保存在assets/config.properties中)。唯一的问题是,您必须以编程方式创建MapView,而不是在xml中创建,因为api密钥只能在构造函数中动态添加。

问题回答

您可以按照以下流程操作

strings.xml文件中添加以下行

<string name="mapkey">your api key</string>

在地图xml中使用以下内容

android:apiKey="@string/mapkey"

因此,开发人员只需要在<code>strings.xml</code>文件中进行更改。

Thanks Deepak

您可以在团队之间共享debug.keystore文件。您可以在项目的根文件夹中找到它。Eclipse不会覆盖它(如果它已经存在),因此您可以使用与伙伴相同的调试密钥库。所以你们都将拥有相同的Map API密钥。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签