Path to document folder

The place to discuss anything and everything about running your LiveCode on Android

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
ameguira@gmail.com
Posts: 20
Joined: Mon Apr 18, 2016 4:57 pm

Path to document folder

Post by ameguira@gmail.com » Fri Aug 09, 2019 11:10 am

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

Klaus
Posts: 11276
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Path to document folder

Post by Klaus » Fri Aug 09, 2019 11:17 am

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

ameguira@gmail.com
Posts: 20
Joined: Mon Apr 18, 2016 4:57 pm

Re: Path to document folder

Post by ameguira@gmail.com » Fri Aug 09, 2019 11:44 am

Thank you Klaus

bogs
Posts: 3939
Joined: Sat Feb 25, 2017 10:45 pm

Re: Path to document folder

Post by bogs » Fri Aug 09, 2019 11:44 am

I do less than nothing with mobile, like Klaus there :D but, reading the dictionary for specialFolderPath it says...
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").
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.

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 -
SparkOut wrote:
Mon Dec 07, 2015 8:33 am
Just 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).
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 of

Code: Select all

 specialFolderPath("documents") & "/Marges.txt" into tFile
try

Code: Select all

 specialFolderPath("documents") & "/marges.txt" into tFile
Image

AxWald
Posts: 368
Joined: Thu Mar 06, 2014 2:57 pm

Re: Path to document folder

Post by AxWald » Fri Aug 09, 2019 12:43 pm

Hi,
Klaus wrote:
Fri Aug 09, 2019 11:17 am
-> 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.
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
This helps determining what is where, and why ;-)

Have fun!
Livecode programming until the cat hits the fan ...

Klaus
Posts: 11276
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Path to document folder

Post by Klaus » Fri Aug 09, 2019 1:34 pm

AxWald wrote:
Fri Aug 09, 2019 12:43 pm
Hi,
Klaus wrote:
Fri Aug 09, 2019 11:17 am
-> 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.
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.
Ah, yes, as I wrote, I don't own any mobile device, so I have no real idea of the "innards" of these things :-)

ameguira@gmail.com
Posts: 20
Joined: Mon Apr 18, 2016 4:57 pm

Re: Path to document folder

Post by ameguira@gmail.com » Fri Aug 09, 2019 2:45 pm

Many thanks for all contributions.
AS we see, it should be simple, but not really..
I will try your solutions
Albert

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5139
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Path to document folder

Post by jacque » Fri Aug 09, 2019 6:02 pm

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

Post Reply

Return to “Android Deployment”