I'm trying to save the Setting in a Local .txt file. But I don't know where i have to put the txt file, that the desktop as well as the android application can find it.
I hope you can help me with this little Problem.
Thanks
For settings, I'd probably just use the LibGDX Preferences interface which works cross-platform. On Android, it uses SharedPreferences, on Desktop it uses an XML file stored in the user's home directory.
The Local file type in LibGDX provides access to the internal app-specific storage (/data/data/com.company.package/files) on Android, and stores the file alongside the jar for Desktop. There is no way to provide a Local file up front at compile time, aside from packing it as an Internal file and extracting it to a Local (or otherwise generating the file with code at run-time).
settings are usually stored using android.content.SharedPreferences:
http://developer.android.com/reference/android/content/SharedPreferences.html
or you can write the txt file to the device, see this tutorial:
http://chrisrisner.com/31-Days-of-Android--Day-23%E2%80%93Writing-and-Reading-Files
Related
I have code for creating an internal file, there is random algorithem that create the data stored in it and i want any app to have the same file with the same binary data in it.
so i need to make the file on my desktop and add it to internal files some how.
my question is what do you think is the best way to do it.
i thought to locate it in my project, read it, and write it to internal files.
the problem is, i dont know where to locate my file in android studio so that it will be included in the external files and then where to read it from.
thanks. =]
hope i made myself clear.
Put it in src/main/assets/.
You can then access your file with AssetManager and do whatever you want with it.
From the Android Developers website:
main/assets/
This is empty. You can use it to store raw asset files. Files that you
save here are compiled into an .apk file as-is, and the original
filename is preserved. You can navigate this directory in the same way
as a typical file system using URIs and read files as a stream of
bytes using the AssetManager. For example, this is a good location for
textures and game data.
You need to move that into the assets folder. From there you can refer to the file.
So I have some files I want my Android App to access, read and write.
I want to store it internally. Where can I put these files in my Java Project so they are accessible or can this not be done?
There are three ways to achieve this, and according to your requirements select the approch
on SDCARD
This is the normal SDCARD/in-build SDCARD in newer smart phones. you need to create specific folder structure and put your files there, here you can do file read and write both
but this in insecure because accessible to all the application
on Internal Storage
This is given as Applicaiton specific storage where you can create the file and do the operation, this is most secure way to do it, but this is generated run time so you can not push the files directly, you can put your files in RAW or ASSETS and copy that here
RAW and ASSETS
This is in the code structure only and only read access is given to this folder, you can not change this file run time.
if you select any one of this approach then simple goggling will show you the sample code.
You can read or write files in the path of your internal storage as
data/data/package_name/files . I had already answered a similar question you can check it out.
I have a short question about writing to a file in android. I am writing a game where I use a xml file to save some data about the level stats. Now I have seen that if I save this xml file in AssetManager it is not possible to change it (only permissions to read files).
Now because I can only modify files which are in the filesystem of android (using openFileInput and openFileOutput to work with it) I wonder where I have to save my (already existing) xml file in my eclipse project so that I can use openFileInput to load it and change it via code.
Do I have to make a new folder? E.g. project_path/files/myxml.xml.
Is it even possible to load a file which was created (outside the AssetManager folder) before installing the .apk to target?
If it is possible does anybody have some example code?
I hope you understand my question.
There is no such place. Installation of android apps does not include an automatic step that would copy your content from apk to the internal folder (and your application does not reside in the folder either).
You will have to create your XML file in code, possibly checking for its existence before each access (or using some other marker).
I have an app that uses native code to generate a .pcap file (amongst other things). The idea is that while running the program, the pcap file is created and I can later retrieve it by say plugging in the phone into my laptop and then access it.
I use fopen(), fwrite() and fclose() in my native code to create the .pcap file. My question is, how should I specify the filename and filepath? For example, when I run it on windows, I just use "test.pcap" and it generates it in the same folder, but how does this work on android? As I mentioned before, the file is created down in native level.
Native or not, the directory structure should be the same.
You can create a directory in /flash called pcap. But check it exists first, as it can be /nand. Use /sdcard if you want to write in the SD card.
After that you can use, say, /flash/pcap/test.pcap as path for the file. The file would be created in the internal flash memory.
Hi fellow android developers!
I am developing an application where I have XML files that contain my data. When doing edits in these data, I save the data to the XML files, thus these must be editable.
This I would be able to achieve using the local storage for my application with the openFileOutput method of my Context.
But how would I go around shipping my program with these datafiles already there, with some pre-filled data?
I can see the option of shipping with some XML files in my res/xml or res/raw, duplicate them to the local data storage, but then I would be unable to remove the files in my resources, and this would take up too much storage.
Please tell me what you would do in this case?
You can not include editable files with your application.
So you will have to write them to the local file system some way. Either by downloading them or including them as raw resources via openRawResource().