Access the expiration information of an expired mobile map package.
Use case
The data contained within a mobile map package (MMPK) may only be relevant for a fixed period of time. Using ArcGIS Pro, the author of an MMPK can set an expiration date to ensure the user is aware the data is out of date.
As long as the author of an MMPK has set an expiration date, the expiration date can be read even if the MMPK has not yet expired. For example, developers could also use this API to warn app users that an MMPK may be expiring soon.
How to use the sample
Run the app. The author of the MMPK used in this sample chose to set the MMPK's map as still readable, even if it's expired. The app presents expiration information to the user.
How it works
Create a MobileMapPackage using the URI to a local .mmpk file and load it.
Use mobileMapPackage.getExpiration() to get the expiration information. Get the expiration message with getMessage() and the expiration date with getDate().
Relevant API
Expiration
MobileMapPackage
Tags
expiration, mmpk
Sample Code
HonorMobileMapPackageExpirationDateSample.java
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Copyright 2019 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.samples.honor_mobile_map_package_expiration_date;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Locale;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Label;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Paint;
import javafx.stage.Stage;
import com.esri.arcgisruntime.loadable.LoadStatus;
import com.esri.arcgisruntime.mapping.Expiration;
import com.esri.arcgisruntime.mapping.ExpirationType;
import com.esri.arcgisruntime.mapping.MobileMapPackage;
import com.esri.arcgisruntime.mapping.view.MapView;
publicclassHonorMobileMapPackageExpirationDateSampleextendsApplication{
private MapView mapView;
private MobileMapPackage mobileMapPackage;
@Overridepublicvoidstart(Stage stage){
try {
// create stack pane and application scene StackPane stackPane = new StackPane();
Scene scene = new Scene(stackPane);
scene.getStylesheets().add(getClass().getResource("/honor_mobile_map_package_expiration_date/style.css").toExternalForm());
// set title, size, and add scene to stage stage.setTitle("Honor Mobile Map Package Expiration Date Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();
// create an overlay to display the expiration information VBox expirationMessageVbox = new VBox(6);
expirationMessageVbox.setBackground(new Background(new BackgroundFill(Paint.valueOf("rgba(0,0,0,0.3)"), CornerRadii.EMPTY,
Insets.EMPTY)));
expirationMessageVbox.setPadding(new Insets(10.0));
expirationMessageVbox.setMaxSize(800, 150);
expirationMessageVbox.setAlignment(Pos.CENTER);
expirationMessageVbox.getStyleClass().add("panel-region");
// create a label to display the expiration message and expiration date Label expirationDetailsLabel = new Label();
expirationMessageVbox.getStyleClass().add("label");
// add the labels to the overlay expirationMessageVbox.getChildren().add(expirationDetailsLabel);
// create a map view mapView = new MapView();
// load the mobile map package File mmpkFile = new File(System.getProperty("data.dir"), "./samples-data/mmpk/LothianRiversAnno.mmpk");
mobileMapPackage = new MobileMapPackage(mmpkFile.getAbsolutePath());
mobileMapPackage.loadAsync();
mobileMapPackage.addDoneLoadingListener(() -> {
// check if the map package has expiration information and if so, has it expired yetif (mobileMapPackage.getExpiration() != null && mobileMapPackage.getExpiration().isExpired()) {
// get the expiration of the mobile map package Expiration expiration = mobileMapPackage.getExpiration();
// get the expiration message String expirationMessage = expiration.getMessage();
// get the expiration date SimpleDateFormat daysHoursFormat = new SimpleDateFormat("EEE',' d MMM yyyy 'at' hh:mm:ss a", Locale.US);
String expirationDate = daysHoursFormat.format(expiration.getDateTime().getTimeInMillis());
// set the expiration message to the label expirationDetailsLabel.setText(expirationMessage + "\n Mobile map package expired on: " + expirationDate + ".");
// load the expired map if it is still accessible after expirationif (mobileMapPackage.getExpiration().getType() == ExpirationType.ALLOW_EXPIRED_ACCESS && mobileMapPackage.getLoadStatus() == LoadStatus.LOADED && !mobileMapPackage.getMaps().isEmpty()) {
// add the map from the mobile map package to the map view mapView.setMap(mobileMapPackage.getMaps().get(0));
// show an alert if the mobile map package is not accessible after expiration } elseif (mobileMapPackage.getExpiration().getType() == ExpirationType.PREVENT_EXPIRED_ACCESS) {
new Alert(Alert.AlertType.ERROR, "The author of this mobile map package has disallowed access after the expiration date.").show();
}
// show the map if it is not expired } elseif (mobileMapPackage.getLoadStatus() == LoadStatus.LOADED && !mobileMapPackage.getMaps().isEmpty()) {
// add the map from the mobile map package to the map view mapView.setMap(mobileMapPackage.getMaps().get(0));
} else {
new Alert(Alert.AlertType.ERROR, "Failed to load the mobile map package.").show();
}
});
// add the map view and overlay to the stack pane stackPane.getChildren().addAll(mapView, expirationMessageVbox);
StackPane.setAlignment(expirationMessageVbox, Pos.CENTER);
} catch (Exception e) {
// on any error, display the stack trace e.printStackTrace();
}
}
/**
* Stops and releases all resources used in application.
*/@Overridepublicvoidstop(){
if (mapView != null) {
mapView.dispose();
}
}
/**
* Opens and runs application.
*
* @param args arguments passed to this application
*/publicstaticvoidmain(String[] args){
Application.launch(args);
}
}