I'm working with osmdroid map in offline mode. I have downloaded tiles using Global mapper and zip tiles are keep in download folder(/sdcard/Download). But on Accessing it getting below error in ArchiveFileFactory of osmdroid. It is Occurring in Android 10 and above.. Given storage access permission also.
ArchiveFileFactory class. Getting Error on highlighted line,
Getting Error On Access Zip File:
Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.osmdroid.tileprovider.modules.ZipFileArchive.toString()
Below is the code:
and build.gradle config is as below
Osm Library:
Tried Both Permissions :
1.Intent.ACTION_OPEN_DOCUMENT_TREE
2.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
Fetching Offline Map
File f = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS) + "/map_file.zip");
if (f.exists()) {
String name = f.getName().toLowerCase();
name = name.substring(name.lastIndexOf(".") + 1);
if (ArchiveFileFactory.isFileExtensionRegistered(name)) {
try {
OfflineTileProvider tileProvider = new OfflineTileProvider(new SimpleRegisterReceiver(getActivity()),
new File[]{f});
mMap.setTileProvider(tileProvider);
String source;
IArchiveFile[] archives = tileProvider.getArchives();
if (archives.length > 0) {
String mapSrc = Preference.getMapSrc(getContext());
if (TextUtils.isEmpty(mapSrc)) {
Set<String> tileSources = archives[0].getTileSources();
if (!tileSources.isEmpty()) {
source = tileSources.iterator().next();
Preference.setMapSrc(getContext(), source);
mMap.setTileSource(FileBasedTileSource.getSource(source));
} else {
mMap.setUseDataConnection(true);
mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
}
} else {
mMap.setTileSource(FileBasedTileSource.getSource(mapSrc));
}
} else {
mMap.setUseDataConnection(true);
mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
return Constant.MAP_ASSETS_KML;
}
clearData();
return Constant.MAP_ASSETS_KML;
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
return Constant.MAP_ASSETS_KML;
}
from Osmdroid offline zip files (tiles) maps does not load on android 10 and 11 devices
No comments:
Post a Comment