I am writing an Android library project. I try to register to Google map and get the API key. I use my certificate information
, meaning that I take a SHA1
fingerprint from my library, and get the API key.
The problem is that I need to write this information in the host application manifest:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY" />
This API key suits my library and not the host application. When I run my library project like a separate application, it works properly
Does anyone has an idea how can I use my api_key
as a library project?
Thanks
The API keys are bound to the package name of the application and the certificate used to sign it (you can use the same key for multiple applications, of course, but you must register each one individually in the Developer Console).
As far as I know, there is no option to provide the key in runtime either. While the now-deprecated V1 API did provide a constructor supplying the key, the new API does not.
Therefore, if what you want to do is distribute a "ready to use" library project with an included API key (yours) for any application, it looks like that's not possible. You need to tell your users to obtain a key, and then include the "com.google.android.maps.v2.API_KEY" entry in their AndroidManifest.xml file.
1.-Put the activity implementing the MapView/FragmentMap into your library. Since the activity would be in a package registered in the Developers's console, it should work. You'll need to merge the manifests.
2.-Name the main package of the final app with the same name of the library's main package. Since the package name is used as a signature for the API key, it may work. You'll need to merge manifests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With