Forum > Android
How to load a binary file from the resources
Kostas:
Hello all!
I have managed to compile the androidlcltest project and run it in my Galaxy Note Smartphone without big problems.
Now i wanted to go a step further and compile my neural network based backgammon engine with lazarus.
So i need to load the file with the paramters of the neural network.
I have put the file in the raw directory and it seems to be added to the apk android file at the end.
How can i now load the file?
To open a file stream does not seem to work, because the parameters file is embedded in the apk file as a resource.
So how can i access these resource data?
Thanks in advance
Kostas
felipemdc:
When the application is installed the APK is uncompressed and the files are stored in the file system. From what I remember resource files will go to a directory /data/data/<package name> maybe /res/ afterwards too. So for the example: /data/data/com.pascal.lcltest/
Using "adb shell" you can access the directory and see for yourself where things are.
Your program always has read/write access to your own directory and you can use TFileStream or anything else to access files there. Later I will check this better, but I thought I'd give a partial answer anyway now as it will probably get you going.
Kostas:
Thanks a lot.
I will try to give it a try as you describe it.
I have i have something new i will let you know.
Regards
Kostas
meanderix:
--- Quote from: Kostas on June 10, 2012, 11:02:07 am ---I have put the file in the raw directory and it seems to be added to the apk android file at the end.
How can i now load the file?
To open a file stream does not seem to work, because the parameters file is embedded in the apk file as a resource.
So how can i access these resource data?
--- End quote ---
Ah, I didn't know about this approach. A different option would be to include the data in a resource script (.rc file.) That should work too.
Mattias
meanderix:
I looked at this further and I don't think the raw files are extracted to /data/data/<packagename>. I think you need to use getResources().openRawResource(R.raw.yourfile) to access the resource file (from the Java side.) However, I would recommend using a resource script since then you can access it directly in pascal.
Navigation
[0] Message Index
[#] Next page