An .mmpk file is an archive containing the data (specifically, basemaps and features) used to display an offline map.
A mobile map package may need to be unpacked to a directory to allow read support for certain data types.
How to use the sample
When the sample opens, it will automatically display the map in the mobile map package. Pan and zoom to observe the data from the mobile map package.
How it works
Create a MobileMapPackage specifying the path to the .mmpk file.
Load the mobile map package with mapPackage.load().
After it successfully loads, get the map from the ".mmpk" and add it to the map view: mapView.map = mapPackage.maps.first().
Relevant API
MapView
MobileMapPackage
About the data
This mobile map package shows points of interest within Yellowstone National Park. It is available for download here on ArcGIS Online.
Tags
mmpk, mobile map package, offline
Sample Code
MainActivity.ktMainActivity.ktDownloadActivity.kt
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* Copyright 2022 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/package com.esri.arcgismaps.sample.displaymapfrommobilemappackage
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.lifecycleScope
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.arcgismaps.mapping.MobileMapPackage
import com.esri.arcgismaps.sample.displaymapfrommobilemappackage.databinding.ActivityMainBinding
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.launch
import java.io.File
classMainActivity : AppCompatActivity() {
privateval provisionPath: String by lazy {
getExternalFilesDir(null)?.path.toString() + File.separator + getString(R.string.app_name)
}
overridefunonCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// authentication with an API key or named user is// required to access basemaps and other location services ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.API_KEY)
// set up data binding for the activityval activityMainBinding: ActivityMainBinding =
DataBindingUtil.setContentView(this, R.layout.activity_main)
// create and add the MapView to the lifecycleval mapView = activityMainBinding.mapView
lifecycle.addObserver(mapView)
// get the file path of the (.mmpk) fileval filePath = provisionPath + getString(R.string.yellowstone_mmpk)
// create the mobile map packageval mapPackage = MobileMapPackage(filePath)
lifecycleScope.launch {
// load the mobile map package mapPackage.load().getOrElse {
showError(it.message.toString(), mapView)
}
// add the map from the mobile map package to the MapView mapView.map = mapPackage.maps.first()
}
}
privatefunshowError(message: String, view: View) {
Log.e(localClassName, message)
Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show()
}
}