如果我沒有記錯,您無法訪問asset文件夾中的.map文件。你必須從那裏複製到SD卡。
private void provideMapData() {
String sourceFile = res.getString(R.array.mapsource);
String destinationFile = res.getString(R.array.mapdestination);
String pathPrefix = activity.getExternalFilesDir(null) + "/";
File directory = new File(pathPrefix);
if (directory.exists() | directory.mkdirs()) {
AssetManager assetManager = activity.getAssets();
InputStream inputStream;
OutputStream outputStream;
File file = new File(pathPrefix + destinationFile);
if (!file.exists()) {
try {
inputStream = assetManager.open(sourceFile);
outputStream = new FileOutputStream(file);
byte[] buffer = new byte[8192];
int read;
while ((read = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, read);
}
inputStream.close();
outputStream.flush();
outputStream.close();
} catch (IOException iOE) {
Log.e("Error: ", "provideMapData()");
}
}
}
}
然後我加載MapDataStore這樣的:
MapDataStore mapDataStore = new MapFile(new File(activity.getExternalFilesDir(null) + "/" + destinationFile));
據this,你應該把這個到您的清單文件:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
這將節省您的明確要求用戶授予WRITE_EXTERNAL_STORAGE權限。
org.mapsforge.map.reader.MapFile來自mapsforge lib而不是來自osmdroid-lib。我修復了問題標籤。我查看了[MapFile.java](https://github.com/mapsforge/mapsforge/blob/master/mapsforge-map-reader/src/main/java/org/mapsforge/map/reader/MapFile.java)我發現沒有需要資產訪問的流api。也許mapsforge有人可以幫助你。 osmdroid-mapsforge-integration目前不支持資產中的mapsforge地圖。如果您瞭解如何操作,請將其添加到此故障單中,以便我們可以將其添加到osmdroid-mapsforge-integration中 – k3b