Page 1 of 1

Copying Files PC <--> Android

Posted: Wed Jun 05, 2013 4:02 pm
by ronn
Is there a direct LiveCode way to copy a file from an Android device to a PC or vice-versa? I know I could e-mail it or use DropBox or use a file manager but this is a frequent requirement and better done without non-LC apps or any manual interaction.

The Android phone/tablet would be attached to the PC via USB. I know the complete source path and the complete target path. But I am apparently too dense to figure out how to do the copy. Doesn't matter to me whether the copying is triggered from the PC or from the Android.

Thanks for any help. (This is going to be embarrassing, isn't it?)

[ LC 6.0.1 Android 4.0.3 ]

... Ron

Re: Copying Files PC <--> Android

Posted: Wed Jun 05, 2013 7:31 pm
by jacque
LOL. I think it's only embarrassing if you already knew the answer and asked anyway. That's what happens to me. :) Goldfish memory.

Code: Select all

put url ("binfile:" & theSourcePath) into url ("binfile:" & theTargetPath)
If the device is mounted on the desktop, that should work.

Re: Copying Files PC <--> Android

Posted: Wed Jun 05, 2013 9:05 pm
by ronn
Thanks for the help, Jacque. Apparently when I said "I know the complete target path", I lied! I've been able to use your method to copy stuff from one place to another if both places are on the same device. But, assuming the source is on Android, how do I specify that the target is to be on the PC and not on the same Android device? Therein lies my confusion.

... Ron

Re: Copying Files PC <--> Android

Posted: Wed Jun 05, 2013 9:51 pm
by jacque
You could use an "ask file" dialog to get the path to the other device/PC. Whatever comes back is what you'd put into the destination variable. On a Mac, it will start with /"Volumes/<drive name>/", on a PC it will start with a drive letter.

You can see what will be returned by entering this in the multi-line pane of the message box:

Code: Select all

ask file "Choose a destination path:"
put it
If you want to calculate a path dynamically in the script, use the above message box test to see what you'd need, and create your own path that follows the same format.

Re: Copying Files PC <--> Android

Posted: Thu Jun 06, 2013 1:15 am
by ronn
Welllll ... afraid I could not get that to work.

• ASK FILE is not supported on Android so I tried it on the PC end of things. While it let me see and choose Android folders through the Windows dialogue, any attempt to enter a file name and Save resulted in a "File not found" error (which seems an odd error for what would be part of a save operation). Interestingly, all of the Android folders also appeared to be empty; folders were shown but no files.

• It still seemed like a good idea so I also tried ANSWER FILE from the PC and selected a file on the Android device. This was a bit more encouraging since it returned something like:
C:/Users/<username>/AppData/Local/Microsoft/Windows/Temporary Internet Files/Content.IE5/GSFIFXB1/samplefile.txt

The second last item (GSFIFXB1) was never consistent though. It changed for a different file in the same folder and even changed for the same file. Samples were GSFIFXB1, V87AC9RC, 1V98KW0K, 5VK5B9Y8. So it doesn't look like I could build a static path into the code.

BTW, trying ANSWER FOLDER and selecting an Android folder always returned a "Folder name is not valid" error.

• The best I seem able to do for now is to, from Windows, have the user select the Android file every time (even though I already know what and where it is). At least that will give me the correct current path so that I can do something like:
answer file "Select file"
put URL ("file:" & it) into URL ("file:C:/TheControlFiles/sample123.txt") -- or wherever I want it

Thanks for your help Jacque. At least I have a way of proceeding now -- but I'm still waiting for someone to say "You're being an idiot! All you have to do is ..."

... Ron

Re: Copying Files PC <--> Android

Posted: Thu Jun 06, 2013 4:34 am
by Simon
Hi Ron,
When connected to a PC, Android's sd card is disabled from the Android device(if that is where you are trying to look). Windows Explorer still see's it but the other way around doesn't work.

Simon

Re: Copying Files PC <--> Android

Posted: Thu Jun 06, 2013 7:42 pm
by jacque
Oh right, you're experiencing the virtual folders that the LiveCode engine creates to simulate "real" folders. I shouldn't give advice without testing it, but I'm about to do it again...

In order to make the specialFolderPaths() work right on mobile, the engine creates "virtual" folders that actually point to other places. On Android that's at:

/data/data/com.yourcompany.yourapp/<foldername>/

So, if you've saved a file in specialfolderpath("documents"), the real folder path will be:

/data/data/com.yourcompany.yourapp/files/

On an unrooted device, you can't look at /data/data/, it's locked, but the files are there. I haven't tried copying one but it's worth a try if you haven't given up yet. I don't know if the PC can see into that folder any more than we can.

Re: Copying Files PC <--> Android

Posted: Fri Jun 07, 2013 2:42 pm
by ronn
[ For anyone still following this sad and heart-wrenching tale ... ]

Think I'm going to have to admit defeat. Having connected an Android phone/tablet to a PC via USB cable, from inside Android I've found no way to copy a file to the PC and from inside the PC I've found no way to read an Android file.

From the Windows side, I can't even see the Android file using the normal File Explorer. I can see the file if it is on the SDCard and I use a program like SnapPea or MyPhoneExplorer so clearly there is some way to do it.

From the Android side, I can use an Android file manager to see the file if it is in a folder on the SDCard but am still unable to copy that file to the PC. As Jacque mentioned, using specialfolderpath("documents") puts the file into "/data/data/..." but again, even though I know it's there, I have come up with no way to copy it to the PC.

BTW, the only Android file manager that let me actually see those "/data/data/..." files was ES File Manager. The device has to be rooted but from that app's Tools menu you can run Root Explorer which lets you see all files. But I still have no way to copy the file to PC.

So unless and until someone comes up with a brilliant idea that actually works, it looks like I'm left with e-mailing or DropBoxing the files between PC and Android. Ugh.

... Ron

Re: Copying Files PC <--> Android

Posted: Fri Jun 07, 2013 7:43 pm
by Simon
Hi Ron,
If it's just getting your app from the PC onto your Android device you just use the device as the Test Target.
Does your mobile show up as a Test Target? Mine does.

Simon

Re: Copying Files PC <--> Android

Posted: Fri Jun 07, 2013 9:23 pm
by ronn
No, there's no problem getting the app onto Android. The problem I'm having is, through Livecode, grabbing a data file that the app creates and copying it from the Android to the PC and vice-versa. I know what and where the file is, but haven't been able to figure out the code to actually copy it to the PC. Any ideas?

Re: Copying Files PC <--> Android

Posted: Sat Jun 08, 2013 1:56 am
by Simon
Hi Ron,
Well, you might not like this but Dropbox does have a REST API:
https://www.dropbox.com/developers/core/docs
It would be really super cool if you integrated that into you app so, say on openStack GET the file and on closeStact PUT the file. If that were on both the mobile and PC you'd be rocking!
Oh, you would have to post a tutorial for all of us afterward.:)

Of course if you have your own server it'd be much easier.

Simon

Re: Copying Files PC <--> Android

Posted: Sat Jun 08, 2013 1:10 pm
by ronn
Hi Simon. There's already a DropBox library for LiveCode at:
http://www.phoenixsea.ch/downloads/Live ... boxLib.zip

I was just looking for a straightforward copy/paste solution for moving files around. Seemed so simple at the time!

Re: Copying Files PC <--> Android

Posted: Sat Jun 08, 2013 8:30 pm
by Simon
Thanks for linking that Ron.
Sorry we couldn't come up with a simple solution.

Simon