5

We are developing an Android application that uses google maps.

Right now, for development purposes, we're using the key like this:

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

And

<string name="google_maps_key">KEY_HERE</string>

For deploying purposes, we will implement a "Bring Your Own Key" approach where each client that buys the product, also put his key to be used.

I know it's weird and somewhat unnecessary, but it is a process from a big company and this decision comes from "the top".

Is there any way that we can have dynamic keys? Like putting a key into a service and consuming it in the app or something like that?

Appreciate any help.

1 Answer 1

5

This is not possible in Google API V2 according to the documentation the API key has to be assigned using the Manifest file.

https://developers.google.com/maps/documentation/android/start#adding_the_api_key_to_your_application

But its possible for MapView.

If you are instantiating a MapView directly from the code, you should pass the Maps API Key in the MapView constructor.

Code:

@Override
protected void onCreate(.....) {
     super.onCreate(....);
     mMapView = new MapView(this, YOUR_MAP_API_KEY); //pass key to MapView Constructor here
     setContentView(mMapView);
  //   ....
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the answer. The option to use a MapView is definitely viable. Is there any drawback of using the map view? I'll wait for a little to see if there are other answers, otherwise will accept yours soon.
In map v2, Constructor has changed "new MapView(this, YOUR_MAP_API_KEY)" does not work, do you any solution for it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.