HERE SDK for Android (Premium Edition)
SDK for Android Developer's Guide

# Embedding the Map Service

## Using a Shared Disk Cache with the Map Service

To embed Map Service, add the following lines inside the <application></application> section in your AndroidManifest.xml file:
<service
android:name="com.here.android.mpa.service.MapService"
android:label="HereMapService"
android:process="global.Here.Map.Service.v3">
<intent-filter>
<!--Note, action name should not be changed.-->
<action android:name="com.here.android.mpa.service.MapService.v3" />
</intent-filter>
</service>
Important: MapService should not be exported and used by other apps.
Important: Starting from v3.15 HERE SDK, MapService intent name must be equal to default one which is 'com.here.android.mpa.service.MapService.v3'. Using another intent name will case SDK initialization failure.

Map Service supports an isolated disk cache, which allows you to set the disk cache to another location such as an SD Card.

Note:
• Migrating the disk cache contents from one location to another is not supported.
• If you are using an SD card, ensure the SD card is always present to avoid any unexpected behavior.
• You should only delete the map data cache when the app is in its early start-up stages, before any HERE SDK calls. Otherwise, map data corruption and unexpected app errors can occur.
• If you plan to support changing the storage location such as switching between internal storage and an SD card, be aware that this requires an app restart, as the storage location switch must be done before initializing MapEngine or AndroidXMapFragment. Also, your manifest entry for the MapService must not contain the process attribute so that the MapService runs in the same process as your app.
• stopService(new Intent(getBaseContext(), com.here.android.mpa.service.MapService.class)) should be called to ensure the map service is shut down properly before the app restarts (for example, using System.exit()), and the disk cache location change can take effect.

Use MapSettings.setIsolatedDiskCacheRootPath(String path) to set desired cache location. It is recommended to set the disk cache location under your application directory if you do not want the cache to persist after your app is uninstalled. This call should occur before MapEngine initialization, otherwise private app's directory will be used for disk cache. For example, if you are modifying the application from the sample tutorial app, you can add the call in the BasicMapActivity.java file before mapFragment.init().

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Search for the map fragment to finish setup by calling init().
mapFragment = (AndroidXMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapfragment);
boolean success = com.here.android.mpa.common.MapSettings.setIsolatedDiskCacheRootPath(
getApplicationContext().getExternalFilesDir(null) + File.separator + ".here-maps");

if (!success) {
// Setting the isolated disk cache was not successful, please check if the path is valid and
// ensure that it does not match the default location
// (getExternalStorageDirectory()/.here-maps).
} else {
mapFragment.init(new OnEngineInitListener() {
...
}
Important: Starting with Android O (8.0), the startService() method now throws an IllegalStateException if an app targeting Android 8.0 tries to use that method in a situation when it isn't permitted to create background services. When an app goes into the background, it has a window of several minutes in which it is still allowed to create and use services. For more information, see Android documentation.

## Incompatibility with Older Versions

Starting from v3.4 HERE SDK is no longer compatible with pre-3.4 versions of the HERE SDK disk cache. Map data downloaded on pre-3.4 versions of HERE SDK cannot be used on v3.4 or later.

If your app uses the isolated disk cache setting as described above, be aware of the following:
• When your users update their pre-3.4 HERE SDK apps to a newer version, their previously downloaded data will be unavailable. This occurs regardless of the fact if the app was automatically or manually updated.
• You can avoid this issue by upgrading the pre-3.4 cache using the DiskCacheUtility.migrate(String sourcePath, String destPath) method. This method takes the same path value as setIsolatedDiskCacheRootPath(String), and it must be run before MapEngine is initialized for the first time.
Note: migrate(String, String) is marked as deprecated because it is offered temporarily to assist with the transition. It will be removed in a future release.
If your app uses the shared disk cache settings as described below, be aware of the following:
• The required <service>...</service> snippet, as described in the previous section, has changed.
• When your users update their pre-3.4 HERE SDK apps to a newer version, their previously downloaded data will be unavailable. This occurs regardless of the fact if the app was automatically or manually updated.
• In the case a user has multiple HERE SDK apps on their system, pre-3.4 apps share one cache, while post-3.4 apps share another.