Device System File Access

I want to allow my users to load files onto their device for my Corona app to use. Searching the forums and on Google I have not found any examples and quite a few “This is not possible!” I find this hard to believe. Could this be the case?

My Android device has a directory on /storage/emulaed/0 (“Device storage”) that contains many directories from many of the apps I have installed. Does Corona allow me to create a directory like this?

I have been able to find the files I use in my app that exist in a sub directory in the same location as my main.lua. I think this location is the system.ResourceDirectory. These are found here:

/data/data/com.domain.name.app/files/coronaResources

I have also located the files that are created in the simulator’s sandbox (Simulator:File>>Show Project Sandbox - Documents). I think this location is the system.DocumentsDirectory. These are found here: 

/data/data/com.domain.name.app/app_data

I can see these because I have rooted my device and am using a root enabled file explorer. Unfortunately, this will not work for a majority of users.

Since almost all of my other apps can create accessible directories, surely this is possible. If this is possible with native code or other frameworks, why not Corona?

If I’m missing something obvious, then where is there a good example of this? OR… Is this on a to do list somewhere?

I’m not familiar with the Apple world, and don’t image that this would be remotely possible there, but I’d like be able to do this for Android and Windows. Can I do this for Windows?

Thanks!!

Officially, out of the box, Corona SDK is only going to give you access to four sandboxed folders:

system.ResourceDirectory – Your apk file, read only

system.DocumentsDirectory – where your app should store permanent files

system.CachesDirectory – where you should store files that can be re-downloaded from the Internet

system.TemporaryDirectory – where you can store files that you don’t care if the system deletes them on you. Android doesn’t really have a concept of a CachesDirectory, I think it maps to system.TemporaryDirectory.

On iOS you cannot access files outside of here, unless you’re using a photo/video picker.

That said, we do support the LFS module and you can form paths to files outside of your sandbox. It is theoretically possible to use the LFS module to access /storage/emulated/0. The problem is this path is not guaranteed to be your writable external data folder.  We have no way to get the path to the device’s storage without using Corona Enterprise.  You might be able to derive some of the varied locations and test them to see if the exist. This will not work on iOS. LFS can only access the sandboxed folders.

Also Corona’s API’s other than io.open and the file i/o APIs, such as audio.loadFile(), display.newImage(), etc. cannot access files outside of the sandbox. If you have an image or sound you want your app to be able to access, you will have to copy the file from your external source and once it’s in one of the three writable system directories, you could then get the Corona API’s access the file.

Rob

Offically

Officially, out of the box, Corona SDK is only going to give you access to four sandboxed folders:

system.ResourceDirectory – Your apk file, read only

system.DocumentsDirectory – where your app should store permanent files

system.CachesDirectory – where you should store files that can be re-downloaded from the Internet

system.TemporaryDirectory – where you can store files that you don’t care if the system deletes them on you. Android doesn’t really have a concept of a CachesDirectory, I think it maps to system.TemporaryDirectory.

On iOS you cannot access files outside of here, unless you’re using a photo/video picker.

That said, we do support the LFS module and you can form paths to files outside of your sandbox. It is theoretically possible to use the LFS module to access /storage/emulated/0. The problem is this path is not guaranteed to be your writable external data folder.  We have no way to get the path to the device’s storage without using Corona Enterprise.  You might be able to derive some of the varied locations and test them to see if the exist. This will not work on iOS. LFS can only access the sandboxed folders.

Also Corona’s API’s other than io.open and the file i/o APIs, such as audio.loadFile(), display.newImage(), etc. cannot access files outside of the sandbox. If you have an image or sound you want your app to be able to access, you will have to copy the file from your external source and once it’s in one of the three writable system directories, you could then get the Corona API’s access the file.

Rob

Offically