Skip To Content ArcGIS for Developers Sign In Dashboard

Open an offline map

You can obtain an offline map using any of these workflows:

If you created the mobile map package with ArcGIS Pro you may need to consider:

If not then proceed to Open the offline map

Unpack a mobile map package

With ArcGIS Pro version 2.1 (or higher) you can include raster datasets in a mobile map package. If this has happened then you must unpack the mobile map package file into a directory before you load it into your app:

  1. Check if you can read the .mmpk file directly by examining the value of MobileMapPackage.isDirectReadSupportedAsync.
  2. If you cannot read the .mmpk file directly then use the unpack method to place the contents of the .mmpk file into a directory.
  3. Instantiate the mobile map package using the directory location.

// Check whether the mobile map package supports direct read
final ListenableFuture<Boolean> directReadSupportedFuture = MobileMapPackage.isDirectReadSupportedAsync(mmpkFileURL);
directReadSupportedFuture.addDoneListener(new Runnable() {
  @Override public void run() {
    // Get the result of the future
    boolean directReadSupported = false;
    try {
      directReadSupported = directReadSupportedFuture.get();
    } catch (InterruptedException | ExecutionException e) {
      dealWithException(e);
    }

    // If the mobile map package supports direct read
    if (directReadSupported) {
      // Create the mobile map package from the .mmpk file
      MobileMapPackage mobileMapPackage = new MobileMapPackage(mmpkFileURL);
      loadMmpk(mobileMapPackage);
    } else {

      // If the mobile map package file does NOT support direct read
      // Unpack the mobile map package file into a directory
      MobileMapPackage.unpackAsync(mmpkFileURL, mmpkDirectoryURL);

      // Create the mobile map package from the unpack directory
      MobileMapPackage mobileMapPackage = new MobileMapPackage(mmpkDirectoryURL);
      loadMmpk(mobileMapPackage);
    }
  }
});

Considerations

Unpacking a mobile map package file into a directory obviously occupies space. You may want to confirm that the device has sufficient space before you unpack the mobile map package file to avoid an unpacking error. To save space you could delete the original mobile map package file after unpacking completes (unless you need this file for another purpose).

Further advice regarding unpacking a mobile map package:

  • If you try to load a mobile map package where direct read is not supported an error will be thrown. The error message will advise you to unpack the mobile map package file.
  • Instead of adding raster data to a scene as an operational or basemap layer you could create a .tpk from raster data and add that to the map before creating the mobile map package. This would avoid the need to unpack the mobile map package.
  • An unpackaged mobile map package takes roughly the same amount of space as the original file.
  • You should confirm that the device has sufficient space before you unpack the mobile map package to avoid an unpacking error.
  • You could delete the original mobile map package file after unpacking completes to save space (unless you need to retain this file for another purpose).
 

Expired mobile map packages

With ArcGIS Pro 2.4 (or later) you can set an expiration date on your mobile map package using some options provided by the ArcGIS Publisher extension. Expiration gives you more control over the lifetime of your data. For example, it will allow you to:

  • Provide data to 3rd party contractors which will expire at the end of a contract.
  • Indicate to your users that frequently changing data has become obsolete.
Use the ArcGIS Pro tool to create the mobile map package and set an expiration date and time, an expiration message and access options if the package has expired. To set these expiration properties ArcGIS Pro must be licensed with the ArcGIS Publisher extension.

As an ArcGIS Runtime developer there are three possible outcomes when you try to load a mobile map package.

  1. You can access the mobile map package. This situation occurs if the mobile map package has not expired or if it has been created without an expiration.
  2. You can access the mobile map package even though the maps and their data have expired. You will be warned that the mobile map package is out of date.
  3. You cannot access the mobile map package because it has expired. In this case the mobile map package will fail to load and you will not be able to access its maps and data.

These three outcomes are managed by the mobile map package load process MobileMapPackage.loadAsync(). No extra workflow or code-paths are required to accommodate these.

You can, however, retrieve the expiration details from the expiration property on the MobileMapPackage if you want to provide your users with extra information. For example, you could display how many days remain before the mobile map package expires:

  1. Load the mobile map package.
  2. Read the expiration property on the mobile map package.
  3. Confirm that the mobile map package has not expired.
  4. Get the expiry date.
  5. Calculate the number of days between today and the expiry date. Report the number of days remaining.

Open the offline map

When your app goes into the field you will need to open the map directly from the mobile map package directory or file stored on your device. To create the mobile map package object, pass the mobile map package directory or file path to the MobileMapPackage constructor.

// Create a MobileMapPackage from the offline map directory path
final MobileMapPackage offlineMapPackage = new MobileMapPackage(mMobileMapPackage);
offlineMapPackage.loadAsync();
offlineMapPackage.addDoneLoadingListener(new Runnable() {
  @Override
  public void run() {
    // Get the title from the package metadata
    System.out.println("Title: " + offlineMapPackage.getItem().getTitle());

    // Get the map from the package and set it to the MapView
    mMapView.setMap(offlineMapPackage.getMaps().get(0));
  }
});

Upon loading the offline map, its metadata is accessible using the ArcGISMap.item property. In some situations, you may want to access the metadata from the mobile map package without loading the map itself. You can access this from the MobileMapPackage.item property.

See Display a map for more details on how to access and display maps stored in mobile map packages.

Next steps

After you have loaded and opened the mobile map package you can continue to work with the maps and follow these steps:

  1. Display and interact with the maps, layers and data offline. Explore and edit the feature data, if necessary.
  2. Update an offline map by synchronizing your edits with the online services when connectivity is restored.
  3. Finish using an offline map to unregistered any geodatabases and fully release all locks on the mobile map package.