Android DocumentsDirectory or other file storage

Here is my code 

[lua]–Function to handle button events
local function handleExportButtonEvent(event)
dataReadyExport()
local phase = event.phase
if “ended” == phase and teamInputBox.text ~= “” and matchInputBox.text ~= “” then
local filePath = system.pathForFile( “Team”… teamInputBox.text … “Match”… matchInputBox.text … “.txt”, system.DocumentsDirectory)
local file, errorString = io.open(filePath, “a”)
if not file then
–error occured; output the cause
print("File error: " … errorString)
else
–write data to file
file:write(
roundedRectBoolText1.text, “\n”,
roundedRectBoolText2.text, “\n”,
roundedRectBoolText3.text, “\n”,
roundedRectBoolText4.text, “\n”,
“\n”,
roundedRectBoolText5.text, “\n”,
roundedRectBoolText6.text, “\n”,
roundedRectBoolText7.text, “\n”,
roundedRectBoolText8.text, “\n”,
“\n”,
roundedRectVarible1.text, “\n”,
roundedRectVarible2.text, “\n”,
“\n”,
roundedRectVarible5.text, “\n”,
roundedRectVarible6.text, “\n”,
“\n”,
roundedRectVarible3.text, “\n”,
roundedRectVarible4.text, “\n”,
“\n”,
commentInputBox.text, “\n”)
–close the file handle
io.close(file)
end
file = nil
resetAllFunction()
print(“Pressed and released!”)
end
handleBackButtonEvent(event)
end
local exportButton = widget.newButton
{
left = sWidth*0.80,
top = sHeight*0.90+sHeight,
width = sWidth*0.15,
height = sHeight*0.07,
defaultFile = “whiteButtonOff.png”,
overFile = “whiteButtonPressed.png”,
label = “Export”,
labelColor =
{
default = {0, 0 , 255},
over = {0, 0, 255},
},
onEvent = handleExportButtonEvent,
}
teleOpGroup:insert(exportButton)
[/lua]

I was wondering where my files are being stored on my android phone. I cant find them anywhere. If there is an alternate way to save files and then be able to open them up either by some sort of file directory app or something that would be great. I want to be able to export this file onto the phone. Find that file in the phone (preferably in the documents folder of my files) and then share that file via bluetooth to my computer. Hopefully I can get a conclusive answer because I really need something and I have been frustrated with it.

Thanks in advance!

It’s really hard to read your code without it being properly indented. Please read: https://coronalabs.com/blog/2015/06/09/tutorial-the-value-of-well-formatted-code/

But your question, where are things stored: They are stored in the App’s sandbox on the device in a place we reference as system.DocumentsDirectory. This is locked in the apps protected sandbox and you can’t access them unless your device has been “rooted”. (Note: we don’t support rooted devices).

On Android, it’s possible to create a path that’s outside your sandbox in the public storage area, but those locations vary from OS to OS. Once the file in a public space, you can use the adb (android debug bridge) tools to copy files off, or other apps that access that area.

But this may not be something you want or expect your users to do.

Rob

Could you point me into the right direction on how I might change the directory/path? Sorry about the code, I never insert it right into the text fields.

Well it looks like you actually did the right forum codes to enter the code. I prefer to press the blue <> button in the edit bar with bold, italics, etc. However, either your code in your editor isn’t indented correctly there, or the indents got lost in the copy/paste.

But on to the issue. In native world, you would call: getExternalFilesDir() from the Environment object. This would get you the right path to external storage. Since the location of this folder has changed over times depending on the version of Android you’re running and other vendor extensions, you can’t assume the file will be in the same place from device to device. For instance, on my Google Nexus 7, its at /storage/sdcard0. Since Corona SDK does not provide an API call to access this, you can’t safely assume this value.

Now if you’re looking to get files yourself while you’re developing it, you can do:

adb shell

which will give you a command line shell on your Android device. You can use Linux commands like “cd” to change directory, “ls” to list files, etc. The adb tools should have a command that lets you download a file once you can find it. Again, the app sandbox will be locked away (system.DocumentsDirectory, system.TemporaryDirectory etc.)

If you want your users to be able to do this explore the “social” plugin and see what it can do for you, though it may be limited to images.

Now of course, this is a limit of Corona SDK. You could do what you want with Corona Enterprise since you would have access to native features.

Rob

Ah, well that’s a shame, I can’t really get Enterprise because I have little money still being in highschool, so there isn’t any way to do this in just regular corona sdk?

No.

It’s really hard to read your code without it being properly indented. Please read: https://coronalabs.com/blog/2015/06/09/tutorial-the-value-of-well-formatted-code/

But your question, where are things stored: They are stored in the App’s sandbox on the device in a place we reference as system.DocumentsDirectory. This is locked in the apps protected sandbox and you can’t access them unless your device has been “rooted”. (Note: we don’t support rooted devices).

On Android, it’s possible to create a path that’s outside your sandbox in the public storage area, but those locations vary from OS to OS. Once the file in a public space, you can use the adb (android debug bridge) tools to copy files off, or other apps that access that area.

But this may not be something you want or expect your users to do.

Rob

Could you point me into the right direction on how I might change the directory/path? Sorry about the code, I never insert it right into the text fields.

Well it looks like you actually did the right forum codes to enter the code. I prefer to press the blue <> button in the edit bar with bold, italics, etc. However, either your code in your editor isn’t indented correctly there, or the indents got lost in the copy/paste.

But on to the issue. In native world, you would call: getExternalFilesDir() from the Environment object. This would get you the right path to external storage. Since the location of this folder has changed over times depending on the version of Android you’re running and other vendor extensions, you can’t assume the file will be in the same place from device to device. For instance, on my Google Nexus 7, its at /storage/sdcard0. Since Corona SDK does not provide an API call to access this, you can’t safely assume this value.

Now if you’re looking to get files yourself while you’re developing it, you can do:

adb shell

which will give you a command line shell on your Android device. You can use Linux commands like “cd” to change directory, “ls” to list files, etc. The adb tools should have a command that lets you download a file once you can find it. Again, the app sandbox will be locked away (system.DocumentsDirectory, system.TemporaryDirectory etc.)

If you want your users to be able to do this explore the “social” plugin and see what it can do for you, though it may be limited to images.

Now of course, this is a limit of Corona SDK. You could do what you want with Corona Enterprise since you would have access to native features.

Rob

Ah, well that’s a shame, I can’t really get Enterprise because I have little money still being in highschool, so there isn’t any way to do this in just regular corona sdk?

No.