0

I'm using osmdroid 5.4.1 lib in android 6.0. I'm asking WRITE_EXTERNAL_STORAGE and ACCESS_COARSE / FINE_LOCATION permissions on realtime. But map not working:

Unable to decode stream: java.io.FileNotFoundException: ... open failed: EACCES (Permission denied)

onRequestPermissionsResult() of the my main Activity calls the following after the user has granted the storage write permission:

public void initTileSources() {
    mMapnikTileSource = new XYTileSource(MAPDIR_MAPNIK, 1, MAXZOOMLEVEL, 256, ".png", new String[]{"http://tile.openstreetmap.de/",
            "http://tile.openstreetmap.org/"});
    mMapView.setTileSource(mMapnikTileSource);

    mSeamarksTileSource = new XYTileSource(MAPDIR_SEAMARK, 1, MAXZOOMLEVEL, 256, ".png", new String[]{
            "http://t1.openseamap.org/seamark/", "http://tiles.openseamap.org/seamark/"});
    TilesOverlay SeamarksOverlay = new TilesOverlay(new MapTileProviderBasic(getActivity(), mSeamarksTileSource), getActivity());
    SeamarksOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
    mMapView.getOverlays().add(SeamarksOverlay);
    // mMapView.invalidate();
}

The mapview only displays the SeamarksOverlay (openseamap) but not the main mMapnikTileSource (openstreetmap). I have to restart the app in order for the mapview to display everything correctly.

I have seen a similar question on stackoverflow but it hasn't been answered.

Can anyone help me? Thanks in advance.

Community
  • 1
  • 1

1 Answers1

0

I'll give you the same answer as the other linked issue. You have to ask for the permissions before the mapview is loaded and displayed.

Either that, or the path for the tile storage cache is read only. On some android devices Environment.getExternalStorageDir returns a read only partition. No clue why, but that will definitely cause issues. It can be overridden with the class OpenStreetMapTileProviderConstants

spy
  • 3,199
  • 1
  • 18
  • 26