AnsweredAssumed Answered

Help with downloading a map for offline use within an app?

Question asked by coracoleman14 on Apr 16, 2018
Latest reply on May 3, 2019 by lobankovanastiaDev

Hello, here is what my code in my onCreate method looks like now (I am following the code found on the Create an offline map guide page). I am using a button to begin the downloading process...I am confused because I do not find that the map is downloaded in the Downloads folder -- this code doesn't do anything but display my portal item:


protected void onCreate(Bundle savedInstanceState) {

    // inflate MapView from layout
    aMapView = (MapView) findViewById(;

    // get the portal url for ArcGIS Online
    aPortal = new Portal(getResources().getString(R.string.portal_url));
    // get the pre-defined portal id and portal url
    aPortalItem = new PortalItem(aPortal, getResources().getString(R.string.webmap_glacier_national_park_id));
    // create a map from a PortalItem
    map = new ArcGISMap(aPortalItem);
    // set the map to be displayed in this view
    Log.d("MAP SET", "we have set our map!");
final Button startdownload = (Button) findViewById(;
startdownload.setOnClickListener(v -> {   
// create an offline map task
        OfflineMapTask offlineMapTask = new OfflineMapTask(map);

        //get all of the preplanned map areas in the web map
        ListenableFuture<List<PreplannedMapArea>> mapAreasFuture = offlineMapTask.getPreplannedMapAreasAsync();
        mapAreasFuture.addDoneListener(() -> {
            try {
                // get the list of areas
                List<PreplannedMapArea> mapAreas = mapAreasFuture.get();

                // loop through the map areas
                for (PreplannedMapArea mapArea : mapAreas) {
                    // load each map area

                    // create the job
                    DownloadPreplannedOfflineMapJob downloadJob =
                            offlineMapTask.downloadPreplannedOfflineMap(mapArea, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString());

                    //start the job

                    // listen for job complete
                    downloadJob.addJobDoneListener(() -> {
                        // get the download result
                        DownloadPreplannedOfflineMapResult downloadResult = downloadJob.getResult();

                        // check for errors
                        if (downloadResult.hasErrors()) {
                            // code here to examine errors:
                            Map<Layer, ArcGISRuntimeException> layerErrors = downloadResult.getLayerErrors();
                            Map<FeatureTable, ArcGISRuntimeException> tableErrors = downloadResult.getTableErrors();

                        } else {
                            // no errors so use the map straight away
                            map = downloadResult.getOfflineMap();


                    mapArea.addDoneLoadingListener(() -> {
                        // get the map area geometry so the is can used to display a graphic on the map
                        Geometry areaGeometry = mapArea.getAreaOfInterest();

                        // get the area title so it can be used in a UI component
                        String areaTitle = mapArea.getPortalItem().getTitle();

                        // UI code for showing map areas goes here:
            } catch (InterruptedException e) {
            } catch (ExecutionException e) {