'Importing' a data file into a Mobile app

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

'Importing' a data file into a Mobile app

Post by Traxgeek » Mon Sep 15, 2014 2:29 pm

HI,

I feel I'm abusing the system here a bit... my apologies :?

I'm trying to get my data, (a sqlite file) created on my desktop whilst creating the initial (desktop) version of my app, into my Android App.
I can e-Mail the data OUT of my mobile app and I can navigate to files created by my mobile app.

What I'd like to be able to do, is be able to get a file created/modified on the desktop back ONTO my mobile app...

It's simple enough on the desktop but, whilst I can pull the SD card out of my Android device and put the file I need onto it, I can't for the life of me find out how to 'see' / navigate around the SD card or whatever I need to do... in order to have the file visible from within my app.
I understand the sandbox system... But...The 'problem' as far as i can see at the moment (the light is VERY dim !! ;-) ) is how to 'see' the SD card from within my mobile app or...

Anyone able to kick me in the right direction please ?
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

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

Re: 'Importing' a data file into a Mobile app

Post by Simon » Mon Sep 15, 2014 6:32 pm

Hi Traxgeek,
This has been asked a bunch of times here in the forums, just do a search.
specialFolderPath("engine")/specialFolderPath("documents")
Copy Files tab in standalone builder.
Forget about trying to search the sd card, new stuff here, I'd like to call it Faith Based Programming :)

Simon
edit;
I can e-Mail the data OUT of my mobile app and I can navigate to files created by my mobile app.
OK so you know where the data ends up, so the last step is the Copy Files tab and "engine" where it ends up.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: 'Importing' a data file into a Mobile app

Post by dave.kilroy » Mon Sep 15, 2014 6:39 pm

Hi Traxgeek

I found this thread from about a year ago that seems to be still current: http://forums.livecode.com/viewtopic.php?f=53&t=15441 where Simon (him again?) and Jacque help out...

The only thing I would add, is to ask you the really dumb question "have you set your app permissions correctly?" (http://livecode.com/developers/guides/m ... plication/)

Dave
"...this is not the code you are looking for..."

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: 'Importing' a data file into a Mobile app

Post by Traxgeek » Mon Sep 15, 2014 10:05 pm

Simon wrote:OK so you know where the data ends up, so the last step is the Copy Files tab and "engine" where it ends up.
I think I explained poorly (again) Sorry... What I'm trying to do is get data from (say) my Mac into my Android. Typically, I can remove the Android's (micro) SD Card, bung it into my Mac, drop a file onto it (in a known location) and shove it back into my Android (maybe a wee bit more gently that I've expressed here) but you get the idea...

What I'm then trying to do on the Android (from within my LC app is locate that SD card so that I can copy the file from it to my app's data folder...
Moving data around witrhin my app's sandbox is pretty simple, it's more how to get outside of it and onto the SD card... But I ma making progress with simply searcing for a folder called X and reporting true or false... There's just one helluva lot of X's to guess... Google's / Forum's been helpful but I haven't struck gold yet although I have been able to build up a kinda folder structure on the internal (I guess) storage card with "/mnt/sdcard/"... I just can't find the external SD card... tried sdcard0, sdcard1, removable etc etc and combinations thereof etc but... no 4 leafed clover... yet !

To make matters slightly more complicated my device has TWO external / removal micro drives (which this is becoming more popular...) So, I'm just learning whilst 'playing' and trying not to get frustrated...

Thanks. I'll let you know how I get on.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

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

Re: 'Importing' a data file into a Mobile app

Post by Simon » Tue Sep 16, 2014 12:41 am

What I'm trying to do is get data from (say) my Mac into my Android. Typically, I can remove the Android's (micro) SD Card,
OK now I may still not be understanding, but...
The Copy Files tab copies a file from your Mac directly into the specialFolderPath ("engine") of your app on your Android.
OK let me check that..
"get data from (say) my Mac..."
OK Copy Files :)
"...into my Android"
specialFolderPath ("engine") :)

"I can remove the Android's (micro) SD Card,..."
Why do that?

"..so that I can copy the file from it to my app's data folder..."
Still... not following. (see above)

Now if you say I want to just interact with the SD card, that is another story and /mnt/sdcard/ is the place.

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

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: 'Importing' a data file into a Mobile app

Post by Traxgeek » Tue Sep 16, 2014 1:07 am

Simon wrote:Now if you say I want to just interact with the SD card, that is another story and /mnt/sdcard/ is the place.
OK, for simplicity that's what I want to do - interact with the SD card !
I haven't explained well, apologies, one last try (but, to be fair, your quote above sums it up adequately) : I have a file on my Mac that was created by my working app (post dev time). I want to be able to transfer that file to a duplicate of the app running on my Android. Not at design time, or immediately thereafter - as an ongoing affair. Say I'm out and about with my Android, I save some data with my app... I can e-mail a zipped version of my new data to my Mac and the App (on the Mac - or PC) will locate and open it (with a little direction from/navigation by me) and that's simple... BUT, when I then want that same data (now modified by the Mac) to be available to the app on my Android... it's not so simple... The simplest way I can come up with is to remove the SD card from my Android, put it into my Mac, dump the modified file from my Mac onto the Android's SD card, pull the SD card out of the Mac and put it back into the Android and then have the app find it and copy it into its working sandbox / docs folder. To be fair I guess it doesn't really matter why---it's the how to pass data, on an ongoing basis, between Mac (or PC) and Android... the reverse way is simple enough. My next step is to be able to e-mail it BACK to the Android and have the app find it... but sandboxing etc means the file is easiest if it's back out on the EXTERNAL SD Card in the 'My Documents' folder or some such...
Simon wrote:/mnt/sdcard/ is the place.
... Unfortunately, this simply points to the INTERNAL SD card (be it an SD card in reality or not). I'm trying to get access to the EXTERNAL SD card... and have tried dozens of guesses as to it's name/path/ID but... so far... to no avail...

I can say that /mnt/, /sdcard/, /mnt/sdcard/ are all resolved to the same INTERNAL SD card but, like I say, I want the EXTERNAL one...

Sorry to be a pain in the proverbial... shouldn't be THAT difficult but it is... The specific Android device is an ASUS Transformer TF701 Infinity on ICS (4.1.1) and it's really annoying me now.... :twisted:

Thanks Simon.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: 'Importing' a data file into a Mobile app

Post by Traxgeek » Tue Sep 16, 2014 1:20 am

Hi Dave,

Thanks for the link - I think I read that one earlier and refused to be demoralised by it... although I do feel for Ronn...

The daft part is Ithe app on the Android can at least 'see' the file & folder structure of the INTERNAL SD Card using (as Simon suggests) the '/mnt/' or '/sdcard/' or '/mnt/sdcard/' path (all three resolve to the same INTERNAL 'SD' card)... works an absolute treat BUT this is still the INTERNAL storage area... I need access to the EXTERNAL card (the one I read/write pretty freely from/to with LC/my app...

I simply can't find (guess and google) the correct path that resolves to the EXTERNAL card.

Like I say, in fact there are 2 SD Cards on the device (giving me 3 in total) and the only one I can actually find a valid path to is the INTERNAL one ! Real simple to test for - with the :

Code: Select all

'if there is a folder "/my_folder_guess" then
     answer 'Whay - found it !"
else
     answer "Have another guess !"
end if
Arrrrghhh !
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

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

Re: 'Importing' a data file into a Mobile app

Post by Simon » Tue Sep 16, 2014 1:25 am

AHHA!
OK then get dropbox :)
or another web server/service and grab the data with "put url". Now it's in your "documents" folder.
Both desktop and mobile will download the file first before it starts any operation.
There is a dropbox thingy around here somewhere for you to upload from mobile (i think).

How is that?

Simon
Edit; here it is
http://forums.livecode.com/phpBB2/viewt ... =4&t=12549
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: 'Importing' a data file into a Mobile app

Post by Traxgeek » Tue Sep 16, 2014 1:32 am

Hi Simon,

I'm not deliberately trying to be difficult - I promise... :wink:

The TF701 doesn't have a data connection. WiFi, yes - but no data.... Sooooo, I guess the DropBox thingy would work - don't mean to sound ungrateful... honestly I don't...

I get so frustrated that a seemingly simple task is so time consuming / difficult - I simply assumed (mother of all c..ups) that someone would have done this... Completely immaterial for iOS so maybe the dropbox method is best... it's just...

Thanks a mil anyways. I appreciate your time and patience.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: 'Importing' a data file into a Mobile app

Post by Mikey » Tue Sep 16, 2014 3:14 pm

It's only easy if you have done it before. The first time it can be hard.

Since we do this multiple times per hour for our own corporate apps (and we're now doing it professionally for other companies),

The paid way:
Contact me off-list and I write the code for you and set it up, etc.


Here's the free way:
1) Look for Gugliermo's dropbox library
2) Add that library into your desktop app and your android app
3) Read up all the discussions on how to set up your app in dropbox
4) Write code on desktop to generate the file
5) If you are paranoid, encrypt the file
6) Encode file so that it transfers properly.
7) Use dropbox library to send file to dropbox
8) Write code to reverse the process in your app.

Once you do it the first time, you're set.

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: 'Importing' a data file into a Mobile app

Post by dave.kilroy » Tue Sep 16, 2014 3:39 pm

Mikey is absolutely right - even with Gugliermo's library getting Dropbox working nicely for you can be quite a bit of effort - but once done it adds really powerful functionality to your apps. The only thing I would add is to also check out EasyJSON by Igor de Oliveira Couto (based on work by Mark Smith and Andre Garzia) which is also free and works nicely with Gugliermo's library

BUT

Can you not connect your Android device to your mac via USB and do the copying that way?

Kind regards

Dave
"...this is not the code you are looking for..."

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: 'Importing' a data file into a Mobile app

Post by Mikey » Tue Sep 16, 2014 4:19 pm

Whoops! Thanks, Dave, I forgot about having to parse the JSON.

When Dropbox sends you directory or file information, it is a JSON array. You then have to parse that to get any information you might want.

Now, if you already know the name of the file, you don't really need that, but if you are sending files periodically, you do need to do that.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: 'Importing' a data file into a Mobile app

Post by jacque » Tue Sep 16, 2014 5:39 pm

I do this all the time using Dropbox without needing the Dropbox library. My method will only work if the file is only created by you, it isn't a generic solution for a public app. If that's your situation then you can do this:

Copy the file to Dropbox on your PC, right click it and get the shared url. Hard - code that into your app in a "get url" statement. Then write the contents of the URL to disk in the app's mobile documents folder.

I use this to keep a personal file updated on my tablet. You could use it in a public app too if you are the only one storing the file. If your app allows users to store their own files then you'll either need to implement the Dropbox library or provide a way for them to enter the Dropbox shared url.

Updating the file in Dropbox doesn't change its url.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: 'Importing' a data file into a Mobile app

Post by Mikey » Tue Sep 16, 2014 6:05 pm

UGH. Something else I forgot. I'm so glad we do this via thread, sometimes. We don't do it the URL way, but our setup is quite a bit more complicated. For fairly simple setups, or to get started, this is a better way to go.

newtronsols
Posts: 192
Joined: Tue Mar 11, 2014 12:57 pm

Re: 'Importing' a data file into a Mobile app

Post by newtronsols » Tue Sep 16, 2014 6:58 pm

If it isn't essential to access the files via SD card why not try: http://livecloud.io/ this works well on Android and desktop.

I don't know how long they're still in beta and can't use commercially - you'd have to ask.

Post Reply