Skip to content

chore(demo): add DemoApplication for API key/Map ID validation#1600

Merged
dkhawk merged 7 commits intomainfrom
chore/better_map_id_handling
Sep 16, 2025
Merged

chore(demo): add DemoApplication for API key/Map ID validation#1600
dkhawk merged 7 commits intomainfrom
chore/better_map_id_handling

Conversation

@dkhawk
Copy link
Copy Markdown
Contributor

@dkhawk dkhawk commented Sep 15, 2025

chore(demo): add DemoApplication for API key/Map ID validation

Introduces a centralized mechanism to validate the Maps API key and configure a Map ID, which is required for features like Advanced Markers.

This change adds a new DemoApplication class that runs two checks on startup:

  • checkApiKey(): Validates that a non-default API key is present in the manifest metadata.
  • getMapId(): Retrieves a Map ID, prioritizing secrets.properties (via BuildConfig) and falling back to strings.xml.

BaseDemoActivity is refactored to:

  • Get the Map ID from DemoApplication.
  • Programmatically create the SupportMapFragment using GoogleMapOptions to apply the mapId.

This replaces the previous method of inflating the map from an XML layout, which didn't allow for easy programmatic Map ID configuration.

Documentation in README.md is updated to reflect the new configuration options for setting the Map ID.

Introduces a centralized mechanism to validate the Maps API key and configure a Map ID, which is required for features like Advanced Markers.

This change adds a new `DemoApplication` class that runs two checks on startup:
- `checkApiKey()`: Validates that a non-default API key is present in the manifest metadata.
- `getMapId()`: Retrieves a Map ID, prioritizing `secrets.properties` (via `BuildConfig`) and falling back to `strings.xml`.

`BaseDemoActivity` is refactored to:
- Get the Map ID from `DemoApplication`.
- Programmatically create the `SupportMapFragment` using `GoogleMapOptions` to apply the `mapId`.

This replaces the previous method of inflating the map from an XML layout, which didn't allow for easy programmatic Map ID configuration.

Documentation in `README.md` is updated to reflect the new configuration options for setting the Map ID.
@googlemaps-bot
Copy link
Copy Markdown
Contributor

Code Coverage

Overall Project 40.12% 🍏

There is no coverage information present for the Files changed

Allows the demo application to run even when a map ID is not provided by instantiating the `SupportMapFragment` without `GoogleMapOptions`.
@dkhawk dkhawk requested a review from kikoso September 15, 2025 23:38
Comment thread README.md
Copy link
Copy Markdown
Collaborator

@kikoso kikoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dkhawk dkhawk merged commit 0aaae62 into main Sep 16, 2025
8 checks passed
@dkhawk dkhawk deleted the chore/better_map_id_handling branch September 16, 2025 13:07
@googlemaps-bot
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.19.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants