Osmdroid 离线 zip 文件(图块)地图无法在 Android 10 和 11 设备上加载
我正在离线模式下使用osmdroid地图。我已经使用全局映射器下载了瓷砖,并且Zip Tiles保留在下载文件夹中(/sdcard/download)。 但是,在访问osmdroid的存档filefactory中,它的访问量低于错误。它发生在Android 10及以上。。给定存储访问权限。
ArchiveFileFactory类。在突出显示的行上获得错误,
在访问zip文件上获取错误:
Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.osmdroid.tileprovider.modules.ZipFileArchive.toString()
以下是代码:
下面
OSM库:
Tried Both Permissions :
1.Intent.ACTION_OPEN_DOCUMENT_TREE
2.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
< a href =“ https://i.sstatic.net/y5ath.png” rel =“ nofollow noreferrer”>
离线图获取
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论