Page 1 of 1

Creating a file on external storage

Posted: Sat Feb 27, 2016 9:39 pm
by okk
Hi,
I want to write application data to a directory on external storage so that it is accessible with Android File Transfer or a similar file browser. Therefor the often mentioned specialFolderPath("Documents") solution is not working for me. What puzzles me is the following:

Code: Select all

put field "data" into URL "file:/mnt/sdcard/Android/data/com.apocalypse.gpstest/data.txt"
actually writes application data into the data.txt file when the file already exists; in my case I copied it from my macbook into the com.apocalypse.gpstest folder using Android File Transfer. But the code doesn't have any effect if the data.txt file doesn't exist yet. So, I can write to an existing file, but I cannot create that file. I am using Android 4.2.2 with LC 8 DP 15.

Thanks for any insights
Oliver

Re: Creating a file on external storage

Posted: Sun Feb 28, 2016 8:02 pm
by jacque
Did you select the option for external storage in the Android pane of the standalone settings? I haven't ever needed to create files there but I'm guessing that would be required.

Re: Creating a file on external storage

Posted: Mon Feb 29, 2016 7:55 am
by okk
Hi,
I have checked "Write External Storage" in the Android standalone setting pane. The curious thing is that I can write to the existing document, so an incorrect filepath cannot be the issue, but I just cannot create the document from within my application. Could you perhaps try if you can create a file somewhere on the external storage. Thanks.
Oliver

Re: Creating a file on external storage

Posted: Mon Feb 29, 2016 7:13 pm
by jacque
I think you've hit an OS restriction. Strong security measures were put in place on kitkat, weakened slightly in lollipop, and completely changed in marshmallow. Samsung implemented their own variations on the rules in some versions of the OS. So you'll get different permissions on different phones depending on several factors.

Android uses the same type of sandboxing as IOS where you can only write to folders owned by the app. See Google:
https://www.google.com/search?q=can+t+w ... &tbs=qdr:y

Re: Creating a file on external storage

Posted: Tue Mar 01, 2016 6:15 pm
by okk
Hi and thanks for the advice. In the moment I cannot test with anything other than Android 4.2. What I actually want to achieve to have a small app that can download large audiofiles (500MB and more) and store those audiofiles on external storage. What is important is that those audio-files are not deleted when I install a new version of the software. I also want that a second application can access those same files.

So how can I make the app "own" folders on external strorage? I thought that the "Write External Storage" is actually exactly about this?

Thanks!
Oliver

Re: Creating a file on external storage

Posted: Tue Mar 01, 2016 8:33 pm
by SparkOut
Each app has its own location, which may or may not be on external storage. Each app has a folder in the sort of path you attempted. This is aliased by specialFolderPath("resources ") -or engine - which is read only, and specialFolderPath(" documents ") which is writable, but only by the parent app.
For writable paths of external storage that can be accessed by different apps, MaxV is the go to guy on Android.
http://forums.livecode.com/viewtopic.ph ... 15#p127466

Re: Creating a file on external storage

Posted: Tue Mar 01, 2016 8:47 pm
by jacque
What is important is that those audio-files are not deleted when I install a new version of the software. I also want that a second application can access those same files.
Regardless of where the files are written, Android will never remove the app data files when the app is updated.

Re: Creating a file on external storage

Posted: Wed Mar 02, 2016 12:40 am
by okk
Hi,
my reference is this info on the android developer pages. http://developer.android.com/training/b ... files.html
The relevant section is >Save a File on External Storage< in the second part of the page. They talk about Public files and Private files saved on external storage. Reading it I was wondering if Livecode would require more Android specific specialFolderPath arguments, e.g. specialFolderPath(" external documents ") that would point to app specific private files on the external storage. Or specialFolderPath(" external public ") that would emulate the getExternalStoragePublicDirectory() method. I am still on Android 4.2. so before the stricter regime with KitKat therefore doubtful that this is a sandboxing issue.

Best
Oliver

Re: Creating a file on external storage

Posted: Wed Mar 02, 2016 7:09 pm
by jacque
I don't know the answer, but requesting another specialFolderPath would be a good feature request in the QCC, and if there's an existing way to do it they'll tell you.

Re: Creating a file on external storage

Posted: Mon Mar 07, 2016 10:57 am
by okk
Hi,
I still tested a bit more and I find out that the issue seems to be with Android File Transfer. The line of code posted in my first post was actually creating a new file "data.txt" on external storage, but Android File Transfer just was not displaying the file. So the file was created but stayed somehow invisible. In any case, the idea with default folder paths to external storage seems reasonable in my opinion. I never feel comfortable to hard-code file paths to an app.

Best
Oliver

Re: Creating a file on external storage

Posted: Sun Aug 18, 2024 6:11 pm
by trevix
Just so that you know:

I was looking for a way, on Android 11, to store outside of the sandbox an UID that wouldn't change when reinstalling my App.
No matter what, I could not write or read a text file in the Document/Dowload/or else folder.
I could just find out if the file existed.

Then, I gave a try with Folders.
So much for the sandbox: I can create/delete and read name of folders in the Document folder (to understand...of Android).
Without any special permission, now I can save my UID string as the name of a created folder, and be sure it want change when deleting the App.
Practically an ID of the device.
Haven't tried yet with Android >13 but it sound promising.

Any comment on this?
Trevix

Re: Creating a file on external storage

Posted: Sun Aug 18, 2024 6:16 pm
by Klaus
Yep, a long standing issue/feature request: https://quality.livecode.com/show_bug.cgi?id=23526

Re: Creating a file on external storage

Posted: Thu Aug 22, 2024 5:59 pm
by trevix
Just so that you know:

I discovered that while it is possible to create a folder on the "Documents" folder (of the OS) on Android 13, the same is not possible on Android 10.
This, more then an Android reverse on security, to me it sounds like a Livecode problem.

Any idea?

Thanks
Trevix