I’ve been looking for external android storage with Corona, and found this plugin:
https://marketplace.coronalabs.com/corona-plugins/android-file-and-uri-manager
His documentation is on this site:
http://cnksoft.es/index.php/otro-software/9-plugin-cnkfilemanager-for-corona
There are even some projects of his own in Github but he does not have exclusive use of the library.getExternalPath … so to do a simple test in which there could be no error, I copied the whole sample code from the corona, (code in which it creates a .txt file in system.DocumentsDirectory) and merged with the sample code of the documentation, then ALL of my test application is this:
local library = require "plugin.cnkFileManager" ------- CODE CORONA SAMPLE -- Get path for file "data.txt" in the documents directory local path = system.pathForFile( "data.txt", system.DocumentsDirectory ) -- Open the file from the path local fh, reason = io.open( path, "r" ) if fh then -- File exists; read its contents into a string local contents = fh:read( "\*a" ) print( "Contents of " .. path .. "\n" .. contents ) else -- File open failed; output the reason print( "File open failed: " .. reason ) -- Create file since it doesn't exist yet fh = io.open( path, "w" ) if fh then print( "Created file" ) else print( "Create file failed!" ) end local numbers = { 1,2,3,4,5,6,7,8,9 } fh:write( "Feed me data!\n", numbers[1], numbers[2], "\n" ) for \_,v in ipairs( numbers ) do fh:write( v, " " ) end fh:write( "\nNo more data\n" ) end ----------------------------- ----------------------------------------- Code Plugin cnkFileManager for Corona local function listener (event) if event.done == "ok" then print ("ok") else print ("ERROR ", event.error) end end library.getExternalPath ( { listener = listener, mainFolder = "NovaPastaT", subFolder = "miPASTA", isPublic = true, isRemovable = false, file = { { filename="data.txt", baseDir=system.DocumentsDirectory }, }, }) io.close( fh ) --native.showAlert( "FOMT", library.getExternalPath, { "OK" } ) FAILED TEST print( path )
my build.settings:
-- -- For more information on build.settings, see the Project Build Settings guide at: -- https://docs.coronalabs.com/guide/distribution/buildSettings -- settings = { orientation = { -- Supported values for orientation: -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight default = "portrait", supported = { "portrait", }, }, -- -- Android section -- android = { usesPermissions = { "android.permission.INTERNET", "android.permission.WRITE\_EXTERNAL\_STORAGE", "android.permission.INSTALL\_PACKAGES", "android.permission.READ\_EXTERNAL\_STORAGE", }, }, -- -- iOS section -- iphone = { xcassets = "Images.xcassets", plist = { UIStatusBarHidden = false, UILaunchStoryboardName = "LaunchScreen", }, }, -- -- Plugins section -- plugins = { ['plugin.cnkFileManager'] = {publisherId = 'es.cnksoft'}, }, -- -- Project section -- excludeFiles = { -- Exclude unnecessary files for each platform all = { "Icon.png", "Icon-\*dpi.png", "Images.xcassets", }, android = { "LaunchScreen.storyboardc", }, }, }
Now, following the documentation logic, it was supposed to be working, but it just does not create the “NovaPastaT” folder and neither the subfolder in my external storage, can anyone tell me what I’m doing wrong? I’ve done a lot of tests and I can not get a positive result.
A test project including exactly these codes is attached to the post.
If anyone realizes where I went wrong and can help me, I’ll be grateful
Edit: It was to be attached, but I could not attach a .rar file, so I’ll send it to mediaFire
Link to download:
http://www.mediafire.com/file/w4n3402st77du80/TesteSalvarDocumentos.rar