Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: automatically choose debug/release Maps api key?

OBSOLETED: this old question refers to obsoleted Google Maps v1 API. When using v2 API, you can use multiple certificate fingerprints in one Google API Console entry. API Key is no longer stored in Manifest nor code.


Is it possible to automatically detect, which certificate was used for signing APK? I'd like to have both debug and release Maps certificates in application and pass valid one to MapView constructor.

With such setup I will not make mistake while releasing application - I'm using debug certificate on emulator and my device, then sign with release one before sending app to Market.

I was thinking about detecting my particular device or whether debugger is connected but it is not perfect. Maybe some file marking need for debug certificate? Is there any better way?

like image 375
tomash Avatar asked Jun 12 '10 19:06

tomash


People also ask

Can I use Google Maps API without API key?

API keys are required for apps and projects that use the Google Maps Platform APIs and SDKs.

Can I get Google Maps API key without billing?

Yes you need to setup a billing account, there is no way around it these days.

Can you expose Google Maps API key?

When you use API keys in your applications, take care to keep them secure. Publicly exposing your credentials can result in your account being compromised, which could lead to unexpected charges on your account.

Are Google Maps API keys secret?

API keys are not strictly secret as they are often embedded into client side code or mobile applications that consume Google Cloud APIs. Still,they should be secured and should never be treated as public information.


1 Answers

There is a new way to determine is it a debug build or release one in SDK Tools, Revision 17. An excerpt from new features overview:

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.

So now you can simply write something like this:

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

UPDATE: I've encountered bug in ADT: sometimes BuildConfig.DEBUG is true after exporting application package. Description is here: http://code.google.com/p/android/issues/detail?id=27940

like image 186
Alexander Mironov Avatar answered Oct 12 '22 13:10

Alexander Mironov