how to read/write data on Android?

J. Landman Gay jacque at hyperactivesw.com
Sun Mar 18 22:58:14 EDT 2012


On 3/18/12 9:35 PM, mikedoub at gmail.com wrote:
> Misery loves company.  I saw your posting this morning so I tried to
> save settings in my app.  No Luck.  I seem to be having the same
> problem.

Here's working code from Casey's Solitaire, built on Android, which 
reads and writes a text file. I don't include the file in Copy Files 
when doing the build, it's created on first launch instead, but I don't 
see why copying it to the app bundle won't work. I add sound files into 
the build with the Copy Files pane and they work okay.


function readPrefsFile -- called elsewhere in the stack
   put getPrefsPath() into tPath
   if there is no file tPath then -- first launch
     put "false,false,false,true,true" into tData
     put tData into url ("file:" & tPath)
   else -- file exists
     put url ("file:" & tPath) into tData
   end if
   return tData
end readPrefsFile

on writePrefsFile pData
   put pData into url ("file:" & getPrefsPath())
end writePrefsFile

function getPrefsPath -- return writable location
   if the environment = "mobile" then
     put specialFolderPath("documents") & slash & "Casey.dat" into tPath
   else -- desktop; use stack folder
     put the effective filename of this stack into tPath
     set the itemDelimiter to "/"
     put "Casey.dat" into last item of tPath
   end if
   return tPath
end getPrefsPath

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list