Read/Write on Android

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
joel.epsteinBUS31vi
Posts: 135
Joined: Thu Sep 13, 2012 10:25 pm

Read/Write on Android

Post by joel.epsteinBUS31vi » Mon Dec 10, 2012 10:15 pm

Hi all -

I know that this has been discussed at length, but despite my best efforts, I can't seem to figure it out.

I want to read and write a simple text file to and from a card field. I know that if I use the "documents" folder, iTunes will back it up during sync. That's cool. So I used this code, which works just great on the Mac and iOS:

Code: Select all

on writeScores
    set the defaultFolder to specialFolderPath("documents")
    put field "scores" of card "Main" into URL ("file:scores.txt")
end writeScores

on readScores
   set the defaultFolder to specialFolderPath("documents")
   put URL ("file:scores.txt") into field "scores" of card "Main"
end readScores
When I try the code on the Android simulator, it simply does not work.
As an attempt to try to track things down, I used the line:
answer the defaultFolder
to which I received:
/data/data/com.yourcompany.yourapp/files

That confused me - not at all what I expected. Is this because I'm running on the simulator, or am I fundamentally doing something wrong? I'd be grateful for any feedback you could offer.

Peace.

Joel

qberty1337
Posts: 35
Joined: Sun Sep 09, 2012 1:09 pm

Re: Read/Write on Android

Post by qberty1337 » Mon Dec 10, 2012 10:24 pm

Your best best is to just use the documents folder in the name of the URL that you are saving to. So:

Code: Select all

put field "scores" of card "Main" into URL ("file:" & specialFolderPath("documents") & slash & scores.txt")
Works for me.

joel.epsteinBUS31vi
Posts: 135
Joined: Thu Sep 13, 2012 10:25 pm

Re: Read/Write on Android

Post by joel.epsteinBUS31vi » Mon Dec 10, 2012 10:59 pm

Fantastic! I appreciate your extremely speedy help. Just what I needed.

Peace.

Joel

Post Reply

Return to “Android Deployment”