My libgdx app can't read "local" file on android. On the libgdx wiki, it says that the local files are stored relative to the application's root or working directory. but i don't know what it is excatly :/
My file is stored in the assets folder in my projet
XmlReader.Element root = reader.parse(Gdx.files.local("gamedata.xml"));
On desktop, this line works well, but on android the app crash because it can't read the file. I tried with Gdx.files.internal
but it's read only and i need to write on this file.
My app have theses permissions (i don't know if its really useful) :
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
What am i doing wrong ? should i store the xml file somewhere else ?
On desktop OS and Android OS the usage of Libgdx is different.
Simply say, there are three storage locations: apk assets(resource) folder , internal storage , external storage . Different storage scheme need different permission.
I suggest you read official doc about File handling , which gives a detailed and good explanation about how to handle file IO via Libgdx on android OS.
To solve my problem, i added an if statement for the first launch.
If there is no local
file, it create one and take data from the internal
one. Then, when the app save, it store data on the local
file.
No permissions needed
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.