Page 1 of 1
Identifier folder not visible
Posted: Mon Jun 25, 2018 3:24 pm
by burkec
Hi folks,
I've been using LiveCode for a few years, but just recently have upgraded to LiveCode Business 9 as I'm trying to make an Android app. I have a program that I made a few years ago that runs on desktop windows/mac that I would like to deploy to mobile.
I've had some problems along the way, but form reading this forum I was able to get around them (thanks

).
My problem at the moment is I'm trying to write a text file to the android phone I'm testing on. I've the following code:
Code: Select all
set the defaultFolder to specialFolderPath("documents")
put gNameofFile into URL("binfile:" & specialFolderPath("documents") & slash & "data.txt")
I can't see this file on the android. I've looked in the phone/Android/data/ and on the sdcard (mnt/sdcard/Android/data/ and can't see my identifier folder. I've changed this to com.zzzzz.zz to make is stand out, but it's not there. Any help as to why my app is not making a folder when I install it would be greatly appreciated.
Thanks,
Colin
Re: Identifier folder not visible
Posted: Mon Jun 25, 2018 3:57 pm
by SparkOut
specialFolderPath ("documents") is a sandboxed location on mobile. You would have to have your phone rooted to be able to use a file explorer to see it from anything other than your app.
You should be able to test reading the file from within your app, or check
Code: Select all
if there is a file specialFolderPath ("documents") & "/data.txt" then...
Alternatively, if you need to make the file available to other apps, you can use an alternate path, which might need a bit of testing - I think it is more consistent these days but in the past it was a bit undetermined whether it was always the same place/alias, but try "/mnt/sdcard/<folder>/<filename>" as the hard coded path without specialFolderPath - this is not the sandboxed "documents" folder.
Re: Identifier folder not visible
Posted: Mon Jun 25, 2018 3:59 pm
by Klaus
Hi burkec,
little hint:
If you provide a full path to the URL function like you do in your example,
then you do not need to set the defaultfolder first!
Best
Klaus
Re: Identifier folder not visible
Posted: Tue Jun 26, 2018 2:34 pm
by burkec
SparkOut and Klaus, thanks for your responses!
I'm still scratching my head a bit, as I can't access the folder (my android is not rooted) nor can I write to the SD card (I've tried loads of different code). I'm deploying to my phone and running tests there. I do have it writing to a file called "testwrite" in defaultFolder("Documents") and then reading from it. I write it and read it to a label and it seems to be working well - using the following code:
Code: Select all
put gCount & comma & gRunTime & comma & gNameOfFile into field "lblTEST"
set the defaultFolder to specialFolderPath("Documents")
put field "lblTEST" into URL ("file:testwrite.txt")
and then wrtiing the contents of "testwrite" to a new label
Code: Select all
set the defaultFolder to specialFolderPath("Documents")
put URL ("file:testwrite.txt") into field "lblTEST2"
I do, however, want to write to a file on the SD and then allow the user to take this and look at it on their computer. This is just one of the issues I'm having.
I'm doing a series of small tests to see if the observational program I made for PC/Mac can be easily deployed for tablets (android).
1) I'm testing playing a movie clip on android - this I have done, but I cannot select a movie from the SDcard yet - I can just bundle it with the program
2) need to calculate playing times when other buttons are pressed and write this an codes to variables (easy part so far!)
3) write this file in SD card (can't do yet) - but have written to defaultFolder("Documents"), so maybe I can transfer it from there (not sure)
If I can do these 3 steps, I can recreate my program.
Thanks again for your help.
Colin
Re: Identifier folder not visible
Posted: Tue Jun 26, 2018 5:45 pm
by jacque
To read and write files outside the sandbox, select the "Write external storage" permission in Android standalone settings. Then in your scripts use specialFolderPath("external documents") to create the file paths.
Re: Identifier folder not visible
Posted: Tue Jul 03, 2018 1:05 pm
by burkec
Thanks Jacque for your reply. I've tried this before and for some reason it;s not working for me.
Thanks again,
COlin
Re: Identifier folder not visible
Posted: Tue Jul 03, 2018 8:10 pm
by jacque
What fails exactly?
I'm not positive, but I believe that Android apps cannot retrieve files from public storage by code. The user has to select them, which gives implicit permission. This is how iOS works, and it's reasonable since allowing any app to read and write files outside the sandbox would allow malware to do the same. Since LC does not provide a file browser for mobile apps, you'd need to write one of your own.