Detecting debug keystore or release keystore programmatically
I was wondering if there was a way to detect if t开发者_如何学Pythonhe 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).
http://daniel-codes.blogspot.com/2011/04/detecting-keystore-signature-in-code.html
This seems like an appropriate method to identify release keys
Also
http://whereblogger.klaki.net/2009/10/choosing-android-maps-api-key-at-run.html
Also
Android: automatically choose debug/release Maps api key?
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).
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.
精彩评论