在其他地方定义 "com.google.android.maps.v2.API_KEY"?

define "com.google.android.maps.v2.API_KEY" somewhere else?

在当前的 Google Android Maps 文档中,"com.google.android.maps.v2.API_KEY" 是在清单文件中定义的。有没有办法将它定义到其他地方?比如在 util 或 java class 文件中?

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

将 API 密钥添加到您的应用程序

按照以下步骤将 API 密钥包含在应用程序的清单中,该清单包含在文件 AndroidManifest.xml 中。地图 API 从那里读取键值并将其传递给 Google 地图服务器,然后确认您可以访问 Google 地图数据。

在 AndroidManifest.xml 中,将以下元素添加为元素的子元素,方法是将其插入到结束标记之前:

<meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="API_KEY"/>
Substitute your API key for API_KEY in the value attribute. This element sets the key com.google.android.maps.v2.API_KEY to the value of your API key, and makes the API key visible to any MapFragment in your application.

保存 AndroidManifest.xml 并重新构建您的应用程序。

Is there a way to define it to somewhere else? like in the util or java class file?

不,因为 Play 服务会在清单中查找它。

现在,据我所知,欢迎您在 res/values/ 目录中的字符串资源中定义 API 键的 剩下的琴弦。您还应该能够在清单合并中使用诸如占位符系统之类的东西来定义 build.gradle 文件中的 API 键。

不,您不能以编程方式设置 Api 键 但是如果你需要使用地图并且你可能需要更改那个 api 键你可以做一些技巧比如添加一些 webView 并填充它 webBased GoogleMap