Creating a file on external storage

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

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
okk
Posts: 136
Joined: Wed Feb 04, 2015 11:37 am

Creating a file on external storage

Post by okk » Sat Feb 27, 2016 9:39 pm

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

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

Re: Creating a file on external storage

Post by jacque » Sun Feb 28, 2016 8:02 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

okk
Posts: 136
Joined: Wed Feb 04, 2015 11:37 am

Re: Creating a file on external storage

Post by okk » Mon Feb 29, 2016 7:55 am

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

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

Re: Creating a file on external storage

Post by jacque » Mon Feb 29, 2016 7:13 pm

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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

okk
Posts: 136
Joined: Wed Feb 04, 2015 11:37 am

Re: Creating a file on external storage

Post by okk » Tue Mar 01, 2016 6:15 pm

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

SparkOut
Posts: 2323
Joined: Sun Sep 23, 2007 4:58 pm

Re: Creating a file on external storage

Post by SparkOut » Tue Mar 01, 2016 8:33 pm

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

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

Re: Creating a file on external storage

Post by jacque » Tue Mar 01, 2016 8:47 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

okk
Posts: 136
Joined: Wed Feb 04, 2015 11:37 am

Re: Creating a file on external storage

Post by okk » Wed Mar 02, 2016 12:40 am

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

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

Re: Creating a file on external storage

Post by jacque » Wed Mar 02, 2016 7:09 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

okk
Posts: 136
Joined: Wed Feb 04, 2015 11:37 am

Re: Creating a file on external storage

Post by okk » Mon Mar 07, 2016 10:57 am

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

Post Reply

Return to “Android Deployment”