Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [Tier 2] Loading .txt file from media folder on Android.

Author
Message
Maindric
15
Years of Service
User Offline
Joined: 22nd Jul 2009
Location:
Posted: 17th May 2015 14:16 Edited at: 17th May 2015 14:33
I found myself needing to find .txt (And eventually, .json) files from my media folder in my games. This works perfect for Windows, but it fails to load in Android. What is the solution to this? Here is my code I am using:



I tried using AppGameKit provided commands to load these files, but I could never get them to work properly. Anyone have any ideas?

Also note, the "SetFolder" command documentation states that the default folder on windows is "C:\Users\username\AppData\AGKApps\appName" which is incorrect. It is actually "C:\Users\username\Documents"
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th May 2015 17:19
Quote: "Also note, the "SetFolder" command documentation states that the default folder on windows is "C:\Users\username\AppData\AGKApps\appName" which is incorrect"


It actually says this is the default write folder for AppGameKit on Windows, not the default Windows folder. So it is correct.

I would suggest using:

std::ifstream stream("\\media\\animationnames.txt");

instead of:

std::ifstream stream("media\\animationnames.txt");

I'm not a C++ coder, but it looks more correct to me.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Maindric
15
Years of Service
User Offline
Joined: 22nd Jul 2009
Location:
Posted: 18th May 2015 11:18
Quote: "std::ifstream stream("\\media\\animationnames.txt");"


I tried that and the files do not load at all, at least on Windows, let me try it on Android.

Also, when I open a file to write without adjusting where to save a file, it saves the file to "C:\Users\username\Documents" by default, so I am not understanding I guess the reference to "C:\Users\username\AppData\AGKApps\appName". I'd rather it save to the AppData folder by default.
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 19th May 2015 01:32 Edited at: 19th May 2015 01:33
Unfortunately it's not straight forward to read files from the APK using standard C++ file commands as the files are actually read directly from the APK which is a compressed file. For reference AppGameKit uses the following commands provided by the Google NDK API to read them

However I wouldn't recommend trying to go down this path. Instead the best way might be to use AppGameKit commands to copy the file to a new name, this will place it in the write folder which is a normal file and its base path can be found with agk::GetWritePath(). That path should be accessible to the normal C++ file commands.

Login to post a reply

Server time is: 2024-11-25 21:46:27
Your offset time is: 2024-11-25 21:46:27