Copying Files in Android

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

interactbooks
Posts: 65
Joined: Thu Oct 07, 2010 4:47 pm

Copying Files in Android

Post by interactbooks » Sat May 21, 2011 9:28 pm

This is just a tip that hopefully will help other LiveCode developers. I am shipping a SQLite database with my application but in order to use the database you have to first copy it out of the application folder which is a read only folder into a folder that permits writes. The file used in this example is called "InteractBooks.rdb"

Here is the line of code that finally made it work.

Code: Select all

 put URL ("binfile:" & specialFolderPath("engine") & "/InteractBooks.rdb") into URL ("binfile:" & specialFolderPath("Documents") & "/InteractBooks.rdb")
Make sure to include the database file (or any other file) as an external.

While this might be a very basic tip for most, I ended up spending a few hours pulling my hair (which I have little left of), trying to figure out how to resolve this issue.

Jason1234
Posts: 42
Joined: Sat Jun 18, 2011 9:20 am

Re: Copying Files in Android

Post by Jason1234 » Sat Dec 31, 2011 12:51 am

Brilliant!

Finally found the post that I needed..after hours of pulling my hair too.
This works great.. thank you so much for the post!

Regards

Jason
Windows / MAC / IOS / Android - Deployment
Build 5.5.4 / & Community Version 6.1

seaniepie
Posts: 154
Joined: Wed Sep 07, 2011 10:56 am

Re: Copying Files in Android

Post by seaniepie » Tue Apr 03, 2012 3:46 pm

You star. It works in iOS also.

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: Copying Files in Android

Post by BarrySumpter » Tue Apr 03, 2012 7:01 pm

Nice contribution! 8)
Very nice.
Many thanks!

There is the technique to
check if db exists
if DB doesn't exist then build the database (on the documents path)
else check for and apply version updates if there are any to existing db.

I haven't had the chance to test the apply version updates
So I don't know how Android handles the replacing a previous version executable with a new one.

Thanks again.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

amsterfrank
Posts: 12
Joined: Thu Dec 09, 2010 11:40 pm
Location: Amsterdam

Re: Copying Files in Android

Post by amsterfrank » Thu Sep 12, 2013 7:34 am

Hi people,
a noobish question, but how to get a database in the specialfolders(engine) location, like interactbooks mentioned in this post ?
I like to start of with a database-model and some records and then have users expand it for themselves and keep it stored.

Thanks in advance. Regards.
Accelerate your Windows system with 9.8 m/s²

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Copying Files in Android

Post by Simon » Thu Sep 12, 2013 7:45 am

You use the "Copy Files" from the standalone settings. :)
Those files end up in the "engine".

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

AndyP
Posts: 614
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Copying Files in Android

Post by AndyP » Thu Sep 12, 2013 8:38 am

Hi interesting thread.
As an addition to this I thought I'd share the code I use for this with the addition of the database connection routine.

The code also differentiates between the code running in the LiveCode IDE and the live environment

In this example the database is named 'AppsAntQWI.sqlite' and I create a subfolder of the documents folder named 'appsant'.

on FirstCreateFiles // Create original startup files if the do not exist
global gDatastore
if the environment is development
then
put specialFolderPath("documents") & slash into FileSrc // for testing
else
put specialFolderPath("engine") & slash into FileSrc // live
end if

put specialFolderPath("documents") & slash & "appsant" & slash into FileDest

// check if folder exists

if there is no folder FileDest then
create folder FileDest
end if

//check if file exists
if there is not a file (FileDest&"AppsAntQWI.sqlite")
then --only copy first time.
put url ("binfile:"&FileSrc&"AppsAntQWI.sqlite") into url ("binfile:"&FileDest&"AppsAntQWI.sqlite")
end if

put FileDest & "AppsAntQWI.sqlite" into gDatastore

end FirstCreateFiles


command DatabaseConnect // Connect to DB
global gConID
global gDatastore
put revOpenDatabase("sqlite",gDatastore, , , , ) into tConID
if tConID is "" then
answer warning "Problem creating or accessing database!"
else
put tConID into gConID
end if
end databaseConnect


Hope this is of some use.
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

amsterfrank
Posts: 12
Joined: Thu Dec 09, 2010 11:40 pm
Location: Amsterdam

Re: Copying Files in Android

Post by amsterfrank » Thu Sep 12, 2013 4:20 pm

Thanks Simon, works like a charm 8)
Accelerate your Windows system with 9.8 m/s²

amsterfrank
Posts: 12
Joined: Thu Dec 09, 2010 11:40 pm
Location: Amsterdam

Re: Copying Files in Android

Post by amsterfrank » Thu Sep 12, 2013 6:10 pm

Ehm, just to double-check some stuff.. because I think I'm messing up things by using 2 X-Code's to be able to render for more simulators (and have used several X-Code's and Livecode's and Simulators in the past) :?

So I have made an example where I added a dbase with Copy Files to the App. Like I said in the post above, that works like a charm. Meaning, when I do the command ( like user 'interactbooks' mentions in the first post here) I actually see the file appearing in the Documents folder in the Application Support for my iPhone Simulators (on Mac).

But here's the thing.. When I rename the original file ( that was supposed to be attached with Copy Files from my /users/frank/Documents folder ) and then run the App again in the Simulator ( without rebuilding anything ) I get an error, stating the file isn't there. That's weird. Simply renaming the file back to the original filename ( as it was as used under Copy Files ) makes it work again.

Ergo, it seems my file isn't really attached to the App's engine folder, but in runtime/simulator it is used as a reference/alias :?: This is because I use Simulator ? Can anyone acknowledge or explain?

Thanks in advance. With regards.
Accelerate your Windows system with 9.8 m/s²

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Copying Files in Android

Post by Simon » Sun Sep 15, 2013 4:59 am

Hi amsterfrank,
I'm not sure I'm clear on this?
Are you changing the name in the bundle after it's been created?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

amsterfrank
Posts: 12
Joined: Thu Dec 09, 2010 11:40 pm
Location: Amsterdam

Re: Copying Files in Android

Post by amsterfrank » Sun Sep 15, 2013 5:20 am

Me neither, Simon :? Thanks for your reply anyways.

I am not changing anything in the bundle after it's been created. When I list the specialfolder(engine) folder it does show up and I can read it. But then I alter the filename that was imported, so not in the app but at the location I imported it from, and then I can't read it no longer and I get an error. Changing the filename back makes the app work again, without restarting, recompling, reimporting anything. So to me it seems that the app is reading the file from my mac's user-folder, and not from within the app (?) Hence this, I am still very noobish on Livecode == I must be doing something stupid..
Accelerate your Windows system with 9.8 m/s²

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Copying Files in Android

Post by Simon » Sun Sep 15, 2013 6:10 am

Hi amsterfrank,
Again I'm not sure I follow you...
Forgive me if this is a dumb question but you don't say that you change the name in the Copy Files as well as at the files location.
Do you?

And since I'm being lame I might as well also say what a great city Amsterdam is! I lived there for a year and walked passed the Anne Frank house probably 100 times and never went in (such an idiot, what a chance I missed). If only the weekends weren't abused by people in the Damrak, ugh it's so embarrassing.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

amsterfrank
Posts: 12
Joined: Thu Dec 09, 2010 11:40 pm
Location: Amsterdam

Re: Copying Files in Android

Post by amsterfrank » Sun Sep 15, 2013 3:22 pm

Simon, no I don't. That's what struck me as weird.
It looks like it's imported to the app, but I'm not reading it back from the App ( but from the original location, from where I imported it ). Although I do use specialfolder(engine), which is mobile-only and should point into my app. Anyways I will extend my script and look better into filepaths to see what I'm doing wrong. Thanks.

P.S. My first name is Frank, not my last :wink: Living here for many years I never visited the Anne Frank House either. However I can suggest the renovated Rijksmuseum and Van Gogh Museum.
Accelerate your Windows system with 9.8 m/s²

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

Re: Copying Files in Android

Post by jacque » Sun Sep 15, 2013 7:11 pm

It does sound like the simulator is using aliases from your description. You can find out by going to the simulator folder and examining the file in there. Get Info on the file and it should tell you if it's an alias.

The odd thing is that I've written many files to mobile special folders and have never seen them turn into aliases. But also, I don't think I ever tried changing the name of the original file, so who knows.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

amsterfrank
Posts: 12
Joined: Thu Dec 09, 2010 11:40 pm
Location: Amsterdam

Re: Copying Files in Android

Post by amsterfrank » Mon Sep 16, 2013 2:44 am

Yes it does seem that the Simulator is working with the 'original file' and not the file that should be included in the app.

So once again explained, I have a file A on in my Mac users/frank/documents folder. I include that to Copy Files and compile it into an app. In the app I show a filelist of specialfolder(engine) and it does show me file A. Then I execute the line like user interactbook shows in the first posting here, and copy it to specialfolder(documents) file B. I see the file B appearing live on my Mac in folder Application Support / Simulators / [iOS version ] / Applications / [myapp] / Documents. It's not an alias. I can connect to file B (a sqlite dbase) and dump the records in an app field. I'm also filelisting the specialfolder(document) and indeed it lists me file B. This all seems correct.

Now I keep the app in the Simulator running and then I change the name of the original file A on my mac, which wás included with Copy Files to the app and shóuld be in specialfolder(engine). I turn back to the running app and click again on my button, which does interactbook's line and then connect to my dbase which now is in specialfolder(documents). In the Application Support / Simulator / [version] / Application / [myapp] / Documents I do see that the file is still there but is suddenly zero bytes in size, and therefor I get a revdberr..

This kind of prooves to me, that the Simulator shows me the file in the specialfolders right, but it's actually using the original file on my mac and not the one that supposed to be included in my app :o

I'm sure this is just Simulator doing this. Or maybe dementia is kicking in early for me? My provisiong profile is outdated at the moment so I can't check on my devices. Please do these steps for yourself and report your findings here..

With regards, Frank
Accelerate your Windows system with 9.8 m/s²

Post Reply

Return to “Android Deployment”