Originally published in the TGC Newsletter – June 1, 2014
The question of transferring data from your mobile app to a server was brought up by Parry on the AGK forums and I thought I’d share my process for getting app data from a device. The problem is that Android and iOS put app data in a protected folder on the device. If you want to root or jailbreak the device it is easy to get at, but this process can be dangerous and complex. If you just need a peek at your app’s data then there is an easier way: add all of the files to a ZIP file and send it to a server.
To start you’ll need a server. You can use your hosted account or a server of your own. If you’re on Windows I highly suggest using XAMPP. The setup is quick and they provide ample information on how to get things going (like allowing outside connections to your server). The next thing you’ll want to do is set up some PHP code on the server to accept files as well as the code in AGK to send the files.
AGK code for sending file:
Ensure that the IP Address 184.108.40.206 is replaced with your own IP address or domain (do not include HTTP://).
PHP code for receiving file:
It’s as simple as that. Just make sure that the “upload” directory is created on your server before trying to send the file. Now that you have all of that set up and tested we’re on to a simple set of code that will get all of the files out of your app’s directory:
As you may imagine you can also do this for every directory and subdirectory for you app’s media folder. It is important to note that the directory you are working with is the write directory for the AGK app and not the read directory. The read directory for apps is where all of the media files exist that you package in with your app. On Android and iOS you do not have access to this directory without rooting/jailbreaking the device. This shouldn’t matter because these files are the same that you packed with the app and you already have those. The write directory is a “sandbox” area where the app is allowed to write data. This is where any file you create with the app will be stored such as data files, debug logs, etc.
This method is extremely helpful when developing your app and when it is actually live. When developing your app you can use this to zip up any debug logs and quickly send them to yourself. When the app is live this can be used to send error reports to you when the user experiences issues. In Wordspionage we use this to send error logs whenever a fatal error occurs. This was extremely helpful in the first few months of our release because a few bugs appeared that did not appear in our extensive beta testing. It allowed us to receive data from our users automatically so they didn’t need to be bothered or actually need to hit a button to send the report. When these error reports are sent to us they also include a screen shot of the game so we can see any visual clues to the issue. This method was paramount to smoothing out the flaws in the game.