Osmdroid - change local map folder - android

I am using offline version of osmdroid, maps are placed in sdcard/osmdroid. Do you know, how to change the file path? I have been searching through their code for handling ZIP files but I haven't found any solution. Anyone faced this issue before?
Thx

If you download the package of code about osmdroid: osmdroid-android-3.0.8-sources, you can open the class OpenStreetMapTileProviderConstants.java and modify the variable in this way:
modify
public static final File OSMDROID_PATH = new File("/mnt/sdcard/osmdroid");
to*
public static final File OSMDROID_PATH = new File("/mnt/ext_sdcard/yourfile");
Then put your map tiles into yourfile.

Here you can check out the code to build your own version of OSMdroid. Changing ZIP and local folder is totally possbile, had to do it myself a few months ago.
Responsible for the Zips are this classes:
org/osmdroid/tileprovider/modules/ZipFileArchive.java
org/osmdroid/tileprovider/modules/MapTileFileArchiveProvider.java

Related

How to change the osmdroid default path to extSdCard?

I would like to know, how to change the osmdroid default path to an extSdCard path?
according to the documentation, it is possible using:
Configuration.getInstance().SetOsmdroidBasePath();
I believe when running my project it automatically starts on the way:
StorageUtils.getStorage().GetAbsolutePath() , "osmdroid"
I tried to use the command below, but my map does not display the tiles
Configuration.getInstance().setOsmdroidBasePath(new File("/mnt/extSdCard/osmdroid"));
And when I debug my code using this: Configuration.getInstance().GetOsmdroidBasePath().GetPath()
It presents the correct path.
It is necessary to perform some reload of my map?
If the user has granted runtime permissions for storage before the map view is created, then it should work just fine. You may want to check to make sure you can write to that path. Android is strange and often times just because a path is available does not mean you can write to it. The StorageUtils class can help you find the available paths and it should be able to determine which path is writable. It is, however, imperfect. Paths can vary from device to device and results can be unpredictable.looking at this link might help you.
For OSM version 6.x you can use the following code
#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);
...
}

ARToolkit: Created new .pat file doesn't work

I'm using ARToolkit in my Android project. I used this to help me create a new marker and everything worked fine. The file created was called marker64.pat. However, the standard pattern files that ARToolkit uses are .patt files (with the extra t). Why did it create a .pat file for me?
This .pat file doesn't seem to work, as it crashes my application just as it starts.
This is the original line of code that was already there (which works fine):
markerID = ARToolKit.getInstance().addMarker("single;Data/hiro.patt;80");
This is my changed version:
markerID = ARToolKit.getInstance().addMarker("single;Data/marker64.pat;80");
This is my marker image whilst I'm creating the marker:
Can you please let me know why, firstly, my file was created as .pat file and not a .patt file. And secondly, why this file doesn't work if it's correct.
Thanks

Get some asset file path in APK

I use some class. That's constructor needs some file path that contains some files.
ex)
Komoran komoran = new Komoran("D:\program_project\lib");
Now I'm making android app. so I can't use absolute path (Because other people who download my app don't have that folder and files)
so I decide to use 'assets' folder that is maybe in APK file. So, final code is like below.
Komoran komoran = new Komoran("file:///android_asset");
but It seems like folder path is wrong(this class doesn't work). What I did wrong ?
This "file:///android_asset" path is used for applications which uses webview ex. cordova/phonegap. As it is part of resources because when Apk is created you can not use this path to access your assets folder. You have to work with context.getResources().getAssets().open("fileName")this code only.
Maybe u can add this code:
context.getResources().getAssets().open("fileName").
u will get a inputstream, and u can do something u want.
No need to use getResources.
You can use directly
context.getAssets().open("fileName").

How to get asset file path in Xamarin?

I have data.xlsx file in Assets folder and need to get its path to apply some library.
Found several solutions here but neither works for me. For example -
File Not Found Exception In Xamarin program
I tried to use file:///android_asset/data.xlsx but here is no file too.
I checked the path with: System.IO.File.Exists(filePath);
So how to get path to this file? Maybe I have to place it in different folder?
Update: possibly I can solve it this way: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
But I can't find where to place it.
Update: this question is about Java and this is unclear how to use this solution in Xamarin.Android: How to get the android Path string to a file on Assets folder?
Looks like the file isn't included in the APK. Ensure that the Build Action of the file in the Asset-folder is set to AndroidAsset.
in general using Xamarin.android , you can use this code :
private string _fileName {get;set;}
public string FileFullPath
{
get
{
return Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures),_fileName);
}
}
Hope it helps.. :)
Looks like it's impossible.
Closest solution is to write file to Cache.

Where should I put static text file?

I wanna include a text file to my project in smartface appstudio. I put it where? In resources folder or assets? FileStream could not read it in resources (as a drawable item). Any idea?
var txtFile = new SMF.IO.FileStream(SMF.IO.applicationResources, "words.txt", SMF.IO.StreamType.read);
txtFile.readToEnd();
It is not implemented in current release of Smartface App Studio. Also I have tried it before. It is Phase 2 for File Operations.
You can download your static text file from the internet and can save it to the local storage. And read it from there. I can just suggest you this idea. Check some helpful links below.
http://developer.smartface.io/hc/en-us/articles/203177557-File-Operations
http://developer.smartface.io/hc/en-us/articles/202153536-File-Download-Upload

Categories

Resources