When I look at my Nexus 9 (Android 7.1.1), I see folders like Download, Movies, Music, Pictures. These are not app sandbox folders. Therefore it has to be external storage.
Rob
When I look at my Nexus 9 (Android 7.1.1), I see folders like Download, Movies, Music, Pictures. These are not app sandbox folders. Therefore it has to be external storage.
Rob
Resource Directory
You can’t modify the resource directory because:
On Android it is not an actual folder.
All mobile OSes lock that folder if it exits at all as a folder. i.e. You can’t create sub-folders in the Resource Directory on iOS.
Other Directories
You can modify Documents, Temporary, etc.
Outside The Sandbox
With regards to making files and folders outside the sandbox area of your app. Unless the device is rooted you probably can’t do that.
However, there may be some plugins to help with this in the marketplace: https://marketplace.coronalabs.com/
One more note. If you do work out the paths and permissions aspect of this, SSK comes with a library for maniuplating files and folders in any OS:
https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/files/
For example, if you knew that this folder existed and was writeable: ‘/storage/emulated/0/’
You could make a sub-folder named ‘bob’ in it like this:
ssk.files.util.mkFolder( '/storage/emulated/0/bob' )
I do not understand why it does not work … I tried the 2 ways presented here, and each one individually did not work. Soon I tried to use SSK and do the following:
local output = "Date" .. ";" .. "Hour" .. ";" .. "Selection" .. "\n" require "ssk2.loadSSK" \_G.ssk.init( { exportSystem = true } ) io.appendFile( output, "testeF.csv" ) ---------------------------------------------------------------- local function listener (event) if event.action == "sent" then print ("file was sent ok") elseif event.action == "cancelled" then print ("file was not sent") end end local library = require "plugin.cnkFileManager" library.copyFileToExternalStorage ( { listener = listener, mainFolder = "FolderOne", subFolder = "FolderTwo", newFileName = "testeF.csv", isPublic = true, isRemovable = false, file = { {filename = "testeF.csv", baseDir = system.ResourceDirectory}, }, })
But nothing happens, no folder is created or anything!
Does anyone know what’s wrong?
*My build.settings:
settings = { orientation = { -- Supported values for orientation: -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight default = "portrait", supported = { "portrait", }, }, -- -- Android section -- android = { usesPermissions = { "android.permission.INTERNET", "android.permission.ACCESS\_FINE\_LOCATION", "android.permission.ACCESS\_COARSE\_LOCATION", "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", }, }, }
My guess (as I said above) is that you don’t have permission to write in that folder.
Also, are you absolutely sure you have the right path?
Regarding your mention of SSK.
As far as I can tell from your code, the only SSK feature you’re using is the io extension to write/append files
You are appending to a file in the system.DocumentsDirectory
io.appendFile( output, "testeF.csv" )
You are not (in that code) using the files library.
But the intention is just to save in Documents, and then use the library.copyFileToExternalStorage to move the file … That’s neither in the code
– edit
even with you putting in bold I could not see where the error is, because I’m actually using the “.library …” = c
Can someone help me ? I have not found the answer so far.
Hi. I think part of the reason nobody is helping is others (like myself) may have a lot of questions about what you want to achieve and why.
Additionally, AFAIK, there is not a lot of uniformity in the file structure of Android file-systems on different manufactures’ devices. i.e. Different devices may have different folder paths to similar storage. This means, coming up with a universal solution may not work in all cases, thus helping write one may lead to you saying, “it doesn’t work on my device.”
I can tell you from experience, nobody who spends time helping by writing a sample wants this to be the end result and response.
So, let me ask some questions and hope that the answers intrigue folks enough for some help to be forthcoming.
On first glance, it seems like a very odd thing to do and a little sketchy. I don’t want to be unkind, but I’m a little hesitant to help write code that can write outside the sandbox and essentially bypass the security of Android.
That said, I’m sure there are many perfectly reasonable uses of this. However, knowing what you want to do, there may be safer and better solutions folks can suggest.
What are the make, model, and Android version of the device(s) you are testing on? Knowing this may help.
Would you consider making, zipping up, then sharing a functional micro project that attempts to do this so folks can directly examine your code?
The only way to solve this problem is by having a real project, so asking for help is essentially asking us to code up a project for you to look at.
I know that I personally, in light of the other challenges of this question I outlined above, can’t spend time on this.
I hope you get help on this, but you may need to make it easier for folks to pitch in and to debug/resolve this.
Cheers,
Ed
Sorry for the delay, I was in college.
1 -
And well, I did not really know that you had this concern if the person will use it for good or ill, I will explain what I am doing:
I have an app that makes it easier for people to fill in boring and repetitive tasks from day to day, after completing everything, this application releases me a .CSV file. Only, let’s agree on one thing. If you put your device on the computer, you want to be easy to find these tables, right? And to get a more beautiful and more professional thing, I’d need a folder inside the root folder. As if it were whatsapp, it only thinks if whatsapp did not create folders, just threw everything there and ready, it would be a terrible mess.
So I want to do just that, I want to create a folder inside the root folder, called “TABLES APP X” and inside this folder, will have a subfolder separating the days. and within these folders of the day, will have the tables in .csv
2 -
MOTO G PLAY, android 7.1.1
3 -
I did not exactly understand this item
One question, would you advise me to delete this topic and open a new one explaining these 2 items?
#3 - Make a sample project that is very very small showing us what you’re trying to do in terms of creating a folder and writing to it. Then zip the project and attach it to this post.
Question: Is your device rooted? If not, I really don’t think Android will let you write to the root folder.
https://www.quora.com/Where-is-the-root-directory-in-android-mobile-phone
No need to start a new thread.
sky roaminggamer! (Brazilian expression, that is to say: My God!)
It’s not in the root folder of the device, but in the INNER folder, the root is a totally different thing. Now I understand the reason for question # 1.
Very sorry ! I meant “How to create a new folder in the device’s internal folder”
very very very very sorry !
Thanks for the link, if not I would be thinking by now that the “root folder” was the “internal folder”
I did some experiments but didn’t really get it working.
At the end I came up with this:
require "ssk2.loadSSK" \_G.ssk.init( { measure = false } ) local files = ssk.files files.util.mkFolder('/storage/emulated/0/bubba') local src = files.resource.getPath("test.csv") local dst = '/storage/emulated/0/bubba/test.csv' files.util.cpFile( src, dst )
Here is my test app: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/07/androidFolderHunting.zip
Here are my results:
PS - It is worth noting, files did not show up right away. There was a several second delay before I could see them from my cable-attached PC.
Yeah, you need to be clear with the words you use.
I know there is a language barrier, but these are technical terms that should be universal across all languages since they are newcomers to the language scene.
(If I’m wrong in this, someone please correct me, but in my experience living and working in foreign countries, other technical Unix/Linux folks knew what I meant when I said ‘root’).
Since we’re talking about Android, I have to assume you know a little bit about Linux and Android. If not, then I understand the confusion.
Note: Your use of the term ‘internal folder’ has no meaning to me. I think perhaps, you mean the ‘internal storage’.
Also, and again, in my experience Android folder systems and hierarchies are NOT consistent so whatever solution you may come up with is simply not going to work universally.
You’re better off coming up with something that works universally, like writing to an Amazon S3 bucket or something like that.
I tried to put this code in the code of my project and it did not work, did not create the folder or anything, I was confused and then I downloaded the example you posted, I created the APK and downloaded it on my cell phone, then gave the following error:
Runtime Error: ssk2 \ files \ RGFiles\_util.lua: 337: can not open /: Permission denied.
(Note: I have agreed the permission for internal storage)
I understand, I will be more careful about the words, I hate to use google translator because it does not translate 100% … Here in Brazil, “Internal folder” and “Internal storage” have the same meaning … Now about root, mine, I confused.
MY GOD, how can it be so hard to write a new folder in the internal android storage ?? I can not imagine why this is practically impossible, I have my head to explode already !!!
Creating folders complexity varies depending on where you’re trying to create them.
Just to clear the language up and make sure we are all talking about the same thing:
root - This is the top-level folder on a device. Unless the device has been hacked (rooted/jailbroken) you cannot write to any arbitrary folder.
app sandbox - This is what I think of when you say “internal folders”. Corona makes five core locations in the sandbox available to you:
system.ResourceDirectory - Where your app’s code, images, and other resources live. You cannot write here. It’s read-only.
system.DocumentsDirectory - You can write files here including making directories. This is where you should store files created by users as well.
system.TemporaryDirectory - A place where you can write files that you have no intention of them lasting for ever.
system.CachesDirectory - A place where you can download files from the Internet to. It’s good for content that is easily replaceable. There is no guarantee these files have permanence either.
system.ApplicationSupportDirectory - A place to store configuration information and other files the app needs that’s not necessarily user data.
See: http://docs.coronalabs.com/api/library/system/index.html#constants
External storage: This is an Android only feature where your device lets you write files too that was originally on the device’s SD card (which on many Android devices is removable). On Android, this is where music, photos, and other large volume data files go. Corona does not officially support External storage. There are a couple of plugins that help here. If you can safely determine the path to external storage then you can create directories here and write files here as well.
Corona makes the lfs.* library available to you which you can use to make directories in any folder you that have write access to.
Rob
Rob, what I want is to create a new folder where you can even create a new folder by your own device, keeping that in mind, I think I’m just searching in the wrong way …
I want to create a new folder in this place here (I’ll explain how to get there because it was too confusing from here already kk)
Settings -> Storage -> Explore (it’s the last option)
Just this, I just need to create a folder there, but to have this whole job, I know it must be VERY simple just because there is an option in the device itself, but until now I have not been able to do this)
Forget the root folder, I do not want to create anything there, it was just a misconception.
I’ve given the idea of moving an application sandbox file over there because I’m not sure if I can create direct .csv in this folder. If you could create it there at once it would be much easier and faster
Looking at my Nexus 9, it appears that is either “External Storage” or something that blends external storage with some access to sandbox folders.
You can look at these plugins:
https://marketplace.coronalabs.com/corona-plugins/external-storage
https://marketplace.coronalabs.com/corona-plugins/android-file-and-uri-manager
You should be able to get the path to external storage from these then use lfs.mkdir() to create a subfolder.
Rob
Many thanks Rob!
But I still persist in doubt, the way:
settings -> storage -> explore
is it called “external storage”?
Did you think it was “internal storage”?