仅使用HERE Android SDK自动补全功能,是否需WRITE_EXTERNAL_STORAGE权限?
Great question—this is a common pain point when using the HERE SDK for specific features without needing full map functionality. Let’s break this down clearly:
What this permission does in the HERE SDK
The WRITE_EXTERNAL_STORAGE permission is tied to the SDK's map asset caching system. By default, the MapEngine tries to set up a cache on external storage for things like map tiles, offline map packages, or cached location metadata. This helps reduce network calls and speed up map-related operations.
Even if you're only using autocomplete (geocoding suggestions), the base MapEngine initialization was built with full map support in mind—so it triggers the permission check automatically, even though your use case doesn't need that cache.
Do you actually need it for autocomplete?
Nope. The autocomplete feature works by making network requests to HERE's servers to fetch suggestions. It doesn't rely on local map assets or external storage caching at all. The permission requirement is just a side effect of the general MapEngine setup, not a hard requirement for the geocoding APIs.
How to skip requesting this sensitive permission
You have two solid options to avoid asking for WRITE_EXTERNAL_STORAGE:
1. Redirect the SDK's cache to internal storage
Your app's internal storage is private and doesn't require any special permissions. You can configure the MapEngine to use this instead of external storage during initialization. Here's a code example:
// Grab your app's private internal cache directory val internalCache = context.cacheDir // Create a dedicated folder for HERE SDK's cache val hereCacheFolder = File(internalCache, "here_autocomplete_cache") hereCacheFolder.mkdirs() // Build a custom configuration pointing to this internal folder val config = MapEngineConfiguration( context, MapEngineConfiguration.DEFAULT_ENVIRONMENT, "YOUR_HERE_API_KEY", hereCacheFolder.absolutePath ) // Initialize MapEngine with this config MapEngine.getInstance().init(config)
This way, the SDK will store any necessary small cache files in your app's private space, and you won't need to request external storage access.
2. Bypass MapEngine entirely with the REST API
If you don't plan to use any other parts of the HERE SDK besides autocomplete, you can skip initializing MapEngine altogether. Instead, call the HERE Geocoding & Search REST API directly. This gives you full control over requests, and you won't have to deal with any SDK-related permission overhead.
You'll send a GET request to the autocomplete endpoint with your API key, search query, and optional location parameters. Just remember to handle network calls on a background thread and parse the JSON response to extract your suggestions.
Quick checks to keep in mind
- Test your implementation thoroughly to make sure autocomplete works smoothly without the permission.
- If you ever add map-related features later, you'll need to revisit the permission requirement at that time.
内容的提问来源于stack exchange,提问作者Markus

