如何将 osmdroid 默认路径更改为 extSdCard?

How to change the osmdroid default path to extSdCard?

我想知道,如何将 osmdroid 默认路径更改为 extSdCard 路径?
根据 documentation,可以使用:

Configuration.getInstance().SetOsmdroidBasePath();

我相信 运行 我的项目会在途中自动启动: StorageUtils.getStorage().GetAbsolutePath() , "osmdroid"

我尝试使用下面的命令,但我的地图不显示图块

Configuration.getInstance().setOsmdroidBasePath(new File("/mnt/extSdCard/osmdroid"));

当我使用这个调试我的代码时:Configuration.getInstance().GetOsmdroidBasePath().GetPath()

它提供了正确的路径。

需要重新加载我的地​​图吗?

如果用户在创建地图视图之前授予了存储的运行时权限,那么它应该可以正常工作。您可能需要检查以确保可以写入该路径。 Android 很奇怪,通常仅仅因为路径可用并不意味着您可以写入它。 StorageUtils class 可以帮助您找到可用的路径,它应该能够确定哪个路径是可写的。然而,它并不完美。路径可能因设备而异,结果可能是 unpredictable.looking,这 link 可能会对您有所帮助。

对于OSM版本6.x你可以使用下面的代码

@Override
    public void onCreate() {
    ...
    org.osmdroid.config.IConfigurationProvider osmConf = org.osmdroid.config.Configuration.getInstance();
    File basePath = new File(getCacheDir().getAbsolutePath(), "osmdroid");
    osmConf.setOsmdroidBasePath(basePath);
    File tileCache = new File(osmConf.getOsmdroidBasePath().getAbsolutePath(), "tile");
    osmConf.setOsmdroidTileCache(tileCache);
    ...
}