Unable to read a file on my device

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jcc75
Posts: 5
Joined: Fri Dec 22, 2017 10:54 pm

Unable to read a file on my device

Post by jcc75 » Sat Dec 23, 2017 8:50 am

Hello.
I can't read a file on my device. I read many topics around here, I tried a lot of solutions, but nothing works for me.
My file "jcc.txt" is in the folder "/Tests".
I tried "file:/Tests/jcc.txt", "file:/mnt/Tests/jcc.txt", "file:/storage/Tests/jcc.txt" (I even tried "file:/storage/emulator/0/...").
Nothing works. I'm really desperate !!!
I know that the paths are not the same into different devices. Mine is a Honor. How can I know the right path to use ?
I need some help, please.
Thanks.

Reading this forum, I also learned that the "answer file", and the other file dialog boxes, don't work on Android. I spent some time studying the LiveCode lessons about "working with files", and I was amazed that the sample scripts didn't work !!! Now I know why !
It would have been nice to specify it in the lessons :evil:

Merry Xmas everybody !!!

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

Re: Unable to read a file on my device

Post by bogs » Sat Dec 23, 2017 9:16 am

What I believe you want to look for in the dictionary is 'SpecialFolderPath', I don't do android, but I know Klaus has posted about this a few times.

Merry Christmas (almost)Image
Image

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Unable to read a file on my device

Post by jmburnod » Sat Dec 23, 2017 12:03 pm

Hi
As bogs said you may use specialfolderpath("documents")
Try this:
put your file "jcc.txt" in documents folder and try this script

Code: Select all

put specialfolderpath("documents") & "/" & "jcc.txt" into tPath
put url ("file:" & tPath
Best regards
Jean-Marc
https://alternatic.ch

jcc75
Posts: 5
Joined: Fri Dec 22, 2017 10:54 pm

Re: Unable to read a file on my device

Post by jcc75 » Sat Dec 23, 2017 1:27 pm

Thank you for your answers.
But this doesn’t work :(
With the jmburnod’s script, tPath returns : /data/user/0/com.yourcompany.yourapp/files/jcc.txt
I think that the folder « documents » refers to the folder « files » which is inside the app folder, and so is not allowed.
The only « data » folder that I can see is inside the Android folder. So I can’t use a relative path to go to the root.
I didn’t think that reading a file with Android was so difficult !

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Unable to read a file on my device

Post by jmburnod » Sat Dec 23, 2017 2:42 pm

Hi
I think that the folder « documents » refers to the folder « files » which is inside the app folder
NO. Documents folder is the folder where your app is
Try this to create a file "jcc.txt" contains "myTest" in folder documents

Code: Select all

put specialfolderpath("documents") & "/" & "jcc.txt" into tPath
put "myTest" into url ("file:" & tPath)
Jean-Marc
https://alternatic.ch

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

Re: Unable to read a file on my device

Post by jacque » Sat Dec 23, 2017 6:34 pm

Android uses a "virtual" file path configuration, and you will not be able to see the file on disk. Don't worry about trying to find it in a file manager, just trust it will be there.

Because these are virtual file paths which exist only in RAM, let LC manage them internally and use specialFolderPath to access them. LC will know where they are. If you want to check, you can use "there is a file..." to see if it's there. Jean-Marc gave an example of how to access a file using specialFolderPath.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jcc75
Posts: 5
Joined: Fri Dec 22, 2017 10:54 pm

Re: Unable to read a file on my device

Post by jcc75 » Sat Dec 23, 2017 7:25 pm

Thank you for your explanations.
I understand now how this works.
I can read my file with the specialfolderpath "engine".
I would have preferred to put my file in some other folder, as an external file, but no matter. I use the "Copy Files" in the Standalone Application Settings, and it works. It's the most important for me.
Thank you again :)
And Merry Christmas !

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

Re: Unable to read a file on my device

Post by jacque » Sat Dec 23, 2017 8:43 pm

You can copy the file from specialFolderPath("resources"), which is where "engine" actually points to, to the folder specialFolderPath("external documents"). That will place it in the visible area of the file system. But you'll need to figure out what the destination file path should be in the external system, and probably will need to create a folder there to hold it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Android Deployment”