-
Notifications
You must be signed in to change notification settings - Fork 981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem loading Mapsforge .map files on Android 10 (api 29) #1591
Comments
@eneiluj Quickly said and probably wrong: what about |
I have no problem to display Mapsforge maps in API 29. I have .map files in the app data storage. |
@mlendl Nice to know it's possible, thanks for the answer. Could you give more details about how you do it? Where exactly did you put the .map file? There is no Osmdroid-related directory in How do you get it and load it in your activity? Are you using |
I have my .map files in SDCARD/Android/data//files/. The file can be directly passed to Mapsforge tile source. Or you can use requestLegacyExternalStorage and put the .map files whereever, but only till august 2020, as Google declared. |
Thanks for the answer.
Did you forget something between
Do you mean you can get a file descriptor of the .map files and then pass them to Could you show me an example?
Yep I'd like to avoid that. |
It should be SDCARD/Android/data/my.app.package/files/ |
Ok thanks a lot. In case other people have trouble managing .map files on Android 10+, here is my feedback: The cleanest way I found to allow users to put .map files in the app data storage is to launch an
File[] externalStorageVolumes = ContextCompat.getExternalFilesDirs(context, null);
File primaryExternalStorage = externalStorageVolumes[0]; to get your app storage.
InputStream inputStream = context.getContentResolver().openInputStream(fileUri);
FileOutputStream outputStream = new FileOutputStream(fdest);
try {
byte[] buffer = new byte[4 * 1024];
int read;
while ((read = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, read);
}
outputStream.flush();
} finally {
inputStream.close();
} It is then easy to scan the app storage to load all .map files with the I guess the issue can be closed. |
Add requestlegacyexternalstorage="true" in manifest.xml |
OK, does that mean that it's no longer possible to share a map between different apps (e.g. Locus, Orux, ...) in Android 10? |
I've just had a look at |
Thanks @monsieurtanuki |
@hgoebl I've not understood 100% so maybe I'm wrong: perhaps you need to create an issue at mapsforge regarding your need to populate |
@monsieurtanuki yes, would be a way. But DocumentFile doesn't expose a File, only an InputStream. mapsforge needs random access (somehow it's a database) and a stream cannot provide random access. So I stay with the solution that users have to reserve enough space so the map-files can be copied to private storage where File-based access will be supported in future releases of Android (most hopefully). It's only a caveat for users with multiple apps and the intention to share .map-files between those apps. TL;DR your ideas are good, but in my opinion it's too risky regarding future Android releases. |
Issue Type
[ ] Question
[x] Bug
[ ] Improvement
[ ] Build system related
[ ] Performance
[ ] Documentation
Description and/or steps/code to reproduce the problem
I'm using Osmdroid in PhoneTrack-Android and everything works fine for Android <= 9.
I can't figure out a way to load Mapsforge .map file in Osmdroid on Android 10. I guess it's caused by the new way of managing storages in Android 10. I saw that things were fixed for tile caching (#1512 #1571).
For the "classic" online tiles providers, it seems the tiles cache is indeed written and red correctly.
So my problem is, first, that the old code sample (findMapFiles method) does not seem to explore the storages according to new Android storage management and fails to find .map files in the default place (
/default-storage/osmdroid/*.map
). It's looking in/storage/emulated/0/osmdroid/
and/mnt/media_rw/1501-3B0F/osmdroid/
on my virtual device and none of that exists or is accessible.My second problem is that I can't find a way to "manually" add a .map file (as a workaround). Even if I create a file descriptor to a .map file using the absolute file path I can get from the adb shell, Osmdroid crashes when I try to display it :
while the file descriptor says the file exists.
I'm currently loosing time and energy trying to convert files Uri (obtained with ACTION_GET_CONTENT intents) to a
File
I could provide to Osmdroid. Probably a dead end 😁.I'll be glad to provide more information if necessary.
Environment
Virtual Android device (API 29) without google services installed.
If it's a bug, version(s) of android this affects:
Android 10 (API level 29)
Version of osmdroid the issue relates to:
v6.1.6
The text was updated successfully, but these errors were encountered: