Path to document folder
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 22
- Joined: Mon Apr 18, 2016 4:57 pm
Path to document folder
Hi Guys
I am trying to read and write a field data into my app in the PreOpenStack and CloseStack handlers.
I am using this script:
//// writing
put specialFolderPath("documents") & "/Marges.txt" into tFile
put the text of fld "results" into url ("file:" & tfile)
/// reading
put specialFolderPath("Documents") & "/Marges.txt" into tFile
set the text of fld "results" of cd "results" to url ("file:" & tfile)
This process works on desktop (I can see my file "Marges") but not on Android
How can I solve this issue
Many thanks to LC community
Albert
I am trying to read and write a field data into my app in the PreOpenStack and CloseStack handlers.
I am using this script:
//// writing
put specialFolderPath("documents") & "/Marges.txt" into tFile
put the text of fld "results" into url ("file:" & tfile)
/// reading
put specialFolderPath("Documents") & "/Marges.txt" into tFile
set the text of fld "results" of cd "results" to url ("file:" & tfile)
This process works on desktop (I can see my file "Marges") but not on Android
How can I solve this issue
Many thanks to LC community
Albert
Re: Path to document folder
Hi Albert,
it DOES work, but not the way you'd exspect it, since "mobile" handles things differently!
-> specialfolderpath("documents") points to a folder inside of your HOME directory on DESKTOP machines!
But on "mobile" this is a folder inside of the APP package, due to security reasons (Sandboxing), which may not be accessible to the users.
I do not own any mobile device, so I cannot give you any further hints, but this is the way "mobile" works!
Best
Klaus
it DOES work, but not the way you'd exspect it, since "mobile" handles things differently!
-> specialfolderpath("documents") points to a folder inside of your HOME directory on DESKTOP machines!
But on "mobile" this is a folder inside of the APP package, due to security reasons (Sandboxing), which may not be accessible to the users.
I do not own any mobile device, so I cannot give you any further hints, but this is the way "mobile" works!
Best
Klaus
-
- Posts: 22
- Joined: Mon Apr 18, 2016 4:57 pm
Re: Path to document folder
Thank you Klaus
Re: Path to document folder
I do less than nothing with mobile, like Klaus there but, reading the dictionary for specialFolderPath it says...
However, I am guessing that it is probably a better bet to save it to the "external documents" of an sd card, if available. I know Jacque expounded on this somewhere on this forum previously, IF I come across it again I'll post a link to it.
Edit - not the link I was looking for, but documents is mentioned in it.
Edit 2 - I also found this explanation by SparkOut -
try
My interpretation of that, assuming the dictionary is right, is that documents *should* be accessible to the user on android, just as it should be almost anywhere else.For Android systems:
engine - The (virtual) path to the engine and its assets.
documents - The path to a folder that can be used for per-application data files.
cache - The path to a folder that can be used for transient per-application data files.
resources - The path to the folder where files and folders are copied in the standalone application (same as the engine folder).
"external documents" - It's the external SD card.
Android Note: An Android application is installed on the phone in the form of its zip package. This means that any assets that are included are not available as discrete files in the native filesystem. In order to manage this the engine essentially 'virtualizes' the asset files you include, allowing (read-only) manipulation with all the standard LiveCode file and folder handling syntax. To access the assets you have included within your application, use filenames relative to specialFolderPath ("engine").
However, I am guessing that it is probably a better bet to save it to the "external documents" of an sd card, if available. I know Jacque expounded on this somewhere on this forum previously, IF I come across it again I'll post a link to it.
Edit - not the link I was looking for, but documents is mentioned in it.
Edit 2 - I also found this explanation by SparkOut -
So, maybe it is just a matter of making sure you have the entire path in lower case? In other words, borrowing your code, instead ofSparkOut wrote: ↑Mon Dec 07, 2015 8:33 amJust for clarity:
specialFolderPath("documents") is a writable location, sandboxed to be accessible only to the app. Other apps will have their own sandboxed documents folder. It is not a generally accessible folder for any and all user documents. The specialFolderPath folders are automatically accessible to you app, but the names are case sensitive (ie lower case only) on mobile (mixed case is OK on desktop, and the paths have different destinations - on desktop "documents" really does mean the user documents folder).
Code: Select all
specialFolderPath("documents") & "/Marges.txt" into tFile
Code: Select all
specialFolderPath("documents") & "/marges.txt" into tFile
Re: Path to document folder
Hi,
OP, you may create an invisible button for your app, and use this code:
This helps determining what is where, and why ;-)
Have fun!
guess you got this mixed up - "documents" is supposed to be the area where user data are to be stored (R/W). It's "resources" and "engine" that are inside the apk, thus read only.
OP, you may create an invisible button for your app, and use this code:
Code: Select all
on mouseUp
put the defaultFolder into myDF
ask "List folder contents:" & CR & "C: cache; D: documents; E: engine;" & CR & \
"F: Fonts; S: Sounds; R: Resources;" & CR & "H: home; S0: SDCard0; S1: SDCard1;" & CR & \
"X: the current DefaultFolder;"
if it is empty then
exit mouseUp
else
put it into what
end if
if what = "C" then
set the defaultfolder to specialfolderPath("cache") & "/"
else if what = "D" then
set the defaultfolder to specialfolderPath("documents") & "/"
else if what = "E" then
set the defaultfolder to specialfolderPath("engine") & "/"
else if what = "F" then
set the defaultfolder to specialfolderPath("engine") & "/fonts/"
else if what = "S" then
set the defaultfolder to specialfolderPath("engine") & "/sounds/"
else if what = "R" then
set the defaultfolder to specialfolderPath("resources") & "/"
else if what = "H" then
set the defaultfolder to specialfolderPath("home") & "/"
else if what = "S1" then
set the defaultfolder to "/storage/sdcard1/"
else if what = "S0" then
set the defaultfolder to "/storage/sdcard0/"
else if what = "X" then
wait 0 with messages -- for "X" we don't need to set DF
else
put "Unrecognized" into what
end if
answer "_Mode: " & what & CR & \
"_Path: " & the defaultfolder & CR & CR & \
"_Files: " & CR & the files & CR & CR & \
"_Folders: " & CR & the folders & CR & CR & "_DF is resetted!"
set the defaultfolder to myDF
end mouseUp
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
Re: Path to document folder
Ah, yes, as I wrote, I don't own any mobile device, so I have no real idea of the "innards" of these things
-
- Posts: 22
- Joined: Mon Apr 18, 2016 4:57 pm
Re: Path to document folder
Many thanks for all contributions.
AS we see, it should be simple, but not really..
I will try your solutions
Albert
AS we see, it should be simple, but not really..
I will try your solutions
Albert
-
- VIP Livecode Opensource Backer
- Posts: 7210
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Path to document folder
I'm pretty sure the problem is case sensitivity, as bogs mentioned. Just change Documents to "documents" and it should work.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 361
- Joined: Wed Apr 27, 2011 2:12 pm
Re: Path to document folder
I know this is an old thread, but I am also having the same problem.
I have the following code:
I only see one file in the app when testing on my LG V30 Android phone. It's called ca-bundle.crt
That is the only file I see in field "fldFiles" from my phone's documents folder. When I use a file manager app and look at the documents folder, my mikefelker.cert file is the only file there. Makes no sense.
I tried "external documents" as well (after I created a documents folder on my external SD card - did not work.
I assume that is my only location I can utilize in my app for outside files.
A typical file would be named firstlast.cert
How can I get that/those .cert files to show up in my android app?
Every else (so far) is working.
Thanks.
Mike
I have the following code:
Code: Select all
on openCard
## List all files in Documents
put files (specialfolderPath("documents") & "/") into tFiles
put tFiles into field "fldFiles"
end openCard
That is the only file I see in field "fldFiles" from my phone's documents folder. When I use a file manager app and look at the documents folder, my mikefelker.cert file is the only file there. Makes no sense.
I tried "external documents" as well (after I created a documents folder on my external SD card - did not work.
I assume that is my only location I can utilize in my app for outside files.
A typical file would be named firstlast.cert
How can I get that/those .cert files to show up in my android app?
Every else (so far) is working.
Thanks.
Mike
-
- VIP Livecode Opensource Backer
- Posts: 7210
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Path to document folder
I don't know the answer but is it possible the files have different permissions? Also, do you know how many files should be there? Does "the detailed files" return a different list? (These are wild guesses.)
Mostly I wanted to warn against using "external documents" going forward. Android 11 has put some restrictions on accessing that folder. I haven't worked out what's required yet.
Mostly I wanted to warn against using "external documents" going forward. Android 11 has put some restrictions on accessing that folder. I haven't worked out what's required yet.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 361
- Joined: Wed Apr 27, 2011 2:12 pm
Re: Path to document folder
No, it's just one file and the permissions are open, so no problem there.
It does not show. I am not using external documents.
At this point, I may have to either have the user choose from a web page or somehow load it in from somewhere else.
I have a feeling I have to use the app to save a file in the documents folder specific to that app.
Totally screwed up. I hate mobile!
Mike
It does not show. I am not using external documents.
At this point, I may have to either have the user choose from a web page or somehow load it in from somewhere else.
I have a feeling I have to use the app to save a file in the documents folder specific to that app.
Totally screwed up. I hate mobile!
Mike
Re: Path to document folder
That's the folder that is referenced by specialFolderPath("documents")karmacomposer wrote: ↑Thu Sep 24, 2020 2:17 amI have a feeling I have to use the app to save a file in the documents folder specific to that app.
The specialFolderPath("external documents") location need permission granted in the Android specific tab of the standalone settings, as well as any inclusions required. Outside LiveCode, this should be referenced by whatever filepath your device uses. I wonder whether you have added a new "documents" folder in a public place on the device that is not the same as the place referenced by LiveCode. Or even that it resolves to /blah/documents/documents now? Or maybe it's the new Android management of external documents, like jacque says.
-
- VIP Livecode Opensource Backer
- Posts: 7210
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Path to document folder
The app-specific documents folder can't be accessed by any other app, it's in a strictly private sandbox. I think that's what you're seeing. The file manager might be looking in the public folder, or maybe it's own. LC is returning the files in your sandbox folder. You can't see that folder in a file manager but you can test it by writing a short text file there and then getting the files to see if the new file is there.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Path to document folder
I would like to mention this strange behaviour (LC 9.6.1RC2 on Android 7.0):
I am saving my App preferences in specialFolderPath("documents") .
On iOS, if I dis install the standalone, I loose my preferences document (as it should).
On Android, somehow, when i reinstall, the standalone find the preferences file and load them. How can this be? Isn't specialFolderPath("documents") deleted when uninstalling the App?
Only if I restart Android, then the prefs are not found (correctly)
Thanks
I am saving my App preferences in specialFolderPath("documents") .
On iOS, if I dis install the standalone, I loose my preferences document (as it should).
On Android, somehow, when i reinstall, the standalone find the preferences file and load them. How can this be? Isn't specialFolderPath("documents") deleted when uninstalling the App?
Only if I restart Android, then the prefs are not found (correctly)
Thanks
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
-
- VIP Livecode Opensource Backer
- Posts: 7210
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Path to document folder
Normally if you uninstall the app, Android will delete all the contents in the app sandbox. But if you install a newer version over the old one, no data is lost. Are you completely uninstalling the first version?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com