Is it possible to set the API v2 key programmatically instead of setting this value in the AndroidManifest file?
I was able to do this with API v1 keys but I can't find some method-constructor in the MapView
to do this with the current API.
Is it possible to set the API v2 key programmatically instead of setting this value in the AndroidManifest file?
I was able to do this with API v1 keys but I can't find some method-constructor in the MapView
to do this with the current API.
AFAIK this is not possible in Google API V2. The documentation suggest the same thing, the API key has to be assigned using the Manifest file:
Changing the Maps API v2 key directly in APK file is possible.
Simply write a script that: unzips the APK, edits binary AndroidManifest to replace predefined value (e.g. XXXXXXX...) with given key, zips it back into .apk.
After that you can normally sign the APK.
according to google's documentation:
Once you have a Maps API Key, you need to reference it from a special attribute -- android:apiKey -- in the MapView element in the XML layout. If you are instantiating a MapView directly from code, you should pass the Maps API Key in the MapView constructor.
So use mapsView's constructor passing your API key. Please review this link for further info
EDIT
here's a code snippet for your problem:
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
String mapApiKey = <your choice logic here>
mMapView = new MapView(this, mapApiKey);
setContentView(mMapView);
}
Use this construct of MapView
public MapView(android.content.Context context,java.lang.String apiKey)
Parameters:
context - A MapActivity object.
apiKey - A Google Maps API Key. See Obtaining a Maps API Key for complete information.
© 2022 - 2024 — McMap. All rights reserved.