5

I was wondering if there was a way to detect if the program is running on the default (debug) keystore (when running from eclipse) or on a signed keystore (when released to Android market)

I use Google Maps in my application and I would like programmatically change the Maps API key appropriately for testing and release since the one API key only works for either testing or release.

There must be a way to do this since Google Maps can detect what keystore was used to compile the application (to enable or disable the maps).

Cœur
  • 37,241
  • 25
  • 195
  • 267
Kurru
  • 14,180
  • 18
  • 64
  • 84
  • Found a Duplicate: http://stackoverflow.com/questions/3029819/android-automatically-choose-debug-release-maps-api-key/3828864#3828864 – Kurru Jun 16 '11 at 22:04
  • this is not an answer to your question, but for others looking for a way to detect debug vs release, try BuildConfig.DEBUG. – Ben H May 30 '13 at 17:06

3 Answers3

1

I don't know how Google Maps does its thing, but here's a possible alternative: You can use the package manager to pull the certificate used to sign the APK and compare it to your known release keystore. I suggest comparing it to this rather than your debug keystore because the debug store expires yearly; your release store will not expire for quite a long time (if you followed Google's guidelines).

mah
  • 39,056
  • 9
  • 76
  • 93
  • Could you provide a code sample? I'm not sure how to use the PackageManager to extract the information of the keystore used – Kurru Jun 15 '11 at 16:38
  • http://daniel-codes.blogspot.com/2011/04/detecting-keystore-signature-in-code.html This looks like that... – Kurru Jun 15 '11 at 22:55
0

Both debug and release keystores are equivalent in their power. The debug keystore is generated automatically by SDK, but you can replace it with any keystore you like (I actually do this to have same debug keystore on my several development machines).

So, in the most general case, there is no distinction between release and debug keystores.

Of cause you can embed the release public key into your application and detect cases when you application is not signed with appropriate private release key. And if so, assume you are in application signed by debug keystore. But I can't say this is an ideal solution, as it has a not so obvious dependency.

inazaruk
  • 74,247
  • 24
  • 188
  • 156
  • any code to start with? I was thinking of having an approach similar to this, just didnt know where to find the relevant functions... – Kurru Jun 15 '11 at 16:30