How to set custom path for Custom Raster Layer in Android 13+ ?
Symptoms / Triggers
-------------------
You may observe one or more of the following issues:
Cache files are not created in the expected directory
Error such as FolderAccessDenied when setting raster cache path
Custom path works on older Android versions but fails on Android 11/12/13+
Raster tiles are not persisted or cache is not reused
* App cannot access /Download or other shared directories
---
Answer (Resolution)
-------------------
On Android 10+ (including Android 13), storage access is restricted due to Scoped Storage.
You cannot reliably use direct filesystem paths like /Download or /storage//...
👉Instead, you must use app-specific storage directories when setting the raster cache path.
---
Recommended Solution
--------------------
### 1. Use an app-specific directory (recommended approach)
Use a directory provided by Android for your app:
File rasterCacheDir = new File(context.getExternalFilesDir(null), "raster_cache");
String path = rasterCacheDir.getAbsolutePath();
Benefits:
Works on Android 10+ without additional permissions
Fully compatible with Scoped Storage
* No manual UUID or path construction required
### 2. Configure raster cache using HERE SDK
private RasterDataSource createRasterDataSource(String dataSourceName, String path) {
String templateUrl = "[https://stamen-tiles.a.ssl.fastly.net/toner](https://stamen-tiles.a.ssl.fastly.net/toner/){z}/{x}/{y}.png";
List storageLevels = Arrays.asList(2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16);
RasterDataSourceConfiguration.Provider rasterProviderConfig =
new RasterDataSourceConfiguration.Provider(
TilingScheme.QUAD_TREE_MERCATOR,
storageLevels,
TileUrlProviderFactory.fromXyzUrlTemplate(templateUrl)
);
rasterProviderConfig.hasAlphaChannel = false;
long maxDiskSizeInBytes = 1024 \* 1024 \* 128; // 128 MB
RasterDataSourceConfiguration.Cache cacheConfig =
new RasterDataSourceConfiguration.Cache(path, maxDiskSizeInBytes);
return new RasterDataSource(
mapView.getMapContext(),
new RasterDataSourceConfiguration(dataSourceName, rasterProviderConfig, cacheConfig)
);
}
### 3. Verify cache location
Build and run the application
Inspect the app-specific storage directory on device/emulator
Raster tiles should be stored under:<br />/Android/data//files/raster_cache/<br />
Summary
-------
Custom raster cache paths may fail on Android 13+ due to storage restrictions.
Use app-specific directories instead of direct filesystem paths
Configure the path using RasterDataSourceConfiguration.Cache
Avoid deprecated storage APIs and hardcoded paths
References:
HERE Documentation – Custom Map Styles (Raster Layers)
HERE SDK - Custom Raster Layers example