how to save data on mobile (android)

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

how to save data on mobile (android)

Post by keram » Mon Apr 07, 2014 7:11 pm

Hello.

I'm trying to save data on mobile (android) but not having any success - it works on Windows though.
The code is here:

Code: Select all

global gAllLines,gMyCategories,gMySelection,gMySelectedLineNrs,gCurrentView,gSFPath

on preopenStack
   local tIndex = 1, tTemp
   set the itemDel to tab  -- or default comma
   if the owner of this stack = empty then  --mainstack
      if the environment is "mobile" then set the fullscreenmode of me to "exactFit"
      
      switch platform() --the platform
         case "mobile"
            ## Android
            put specialFolderPath("documents") into gSFPath
            break
         case "Win32"
            ## Everything >= Win2000
            if the systemversion contains "NT" then put specialFolderPath(26) into gSFPath
            break
         case "MacOS"
            ## MacOS X
            put specialFolderPath("preferences") into gSFPath
            break
      end switch
      
      put gSFPath &"/MQdata" into gSFPath
      
      if there is not a folder gSFPath then new folder gSFPath  --new folder
      if result() <> empty then answer "Sorry, but there was a problem writing to a .ini file." with "OK"
      
      put empty into gAllLines
      put fld "Data" into gAllLines
      
      if there is no file (gSFPath &"/Selection.ini") then
         put empty into gMySelection
         repeat for each line i in gAllLines
            put item 1 of i & tab & item 2 of i & return after gMySelection
            add 1 to tIndex
         end repeat
         delete char -1 of gMySelection--***return char too
         put gMySelection into URL ("file:" & gSFPath &"/Selection.ini")
         
      else
         put URL ("file:" & gSFPath &"/Selection.ini") into gMySelection
         
         ## refresh gAllLines:
         put empty into gMySelectedLineNrs
         repeat for each line i in gMySelection
            if item 2 of i is "true" then
               put item 1 of i & tab after gMySelectedLineNrs 
            end if
         end repeat
         delete char -1 of gMySelectedLineNrs  --tab
         
         repeat for each line i in gAllLines
            if item 1 of i is among the items of gMySelectedLineNrs then 
               put "true" into item 2 of i
            end if
            put i & cr after tTemp
         end repeat
         delete char -1 of tTemp  --cr
         put tTemp into gAllLines
      end if
      
      if there is no file (gSFPath &"/AppsData.ini") then
         put empty into gMyCategories
         set the hilite of btn "s"  to true
         set the hilite of btn "m"  to true
         set the hilite of btn "l" to true
         put "s" & tab after gMyCategories
         put "m" & tab after gMyCategories
         put "l" & tab after gMyCategories
         put gMyCategories into URL ("file:" & gSFPath &"/AppsData.ini")
      else
         put empty into gMyCategories
         put URL ("file:" & gSFPath &"/AppsData.ini") into gMyCategories
         set the hilite of btn "s"  to ("s" is among the items of gMyCategories)
         set the hilite of btn "m" to ("m" is among the items of gMyCategories)
         set the hilite of btn "l" to ("l" is among the items of gMyCategories)
      end if
   end if
   send mouseUp to btn "All Lines"
   pass preopenStack
end preopenStack
Please let me know where to correct the code to get it working on Android.

Thanks.

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

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

Re: how to save data on mobile (android)

Post by dave.kilroy » Mon Apr 07, 2014 8:05 pm

Hi Keram

It's been almost a year since I last built for Android so I won't comment on your code except to say at first blush it looks pretty ok (but obviously it's not)

However, what would help others with more recent experience of Android to help you is some more information:

How exactly did it fail on Android? What error message (if any) did you get? Did you try inserting some 'answer' calls in your script to see how far you got and to check out values in variables? Can you confirm whether your paths are OK and did your "MQData" folder get created on your device? Ditto for your .ini file? What platform are you building on? What version of LC? etc etc.

Kind regards

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

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: how to save data on mobile (android)

Post by LCNeil » Mon Apr 07, 2014 9:04 pm

Hi Keram,

Writing to Android will also not work if you do not have "Write External Storage" checked within your Android Standalone Application Setting. Please ensure this is checked before testing on your Android device.

Kind Regards,


Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
——

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: how to save data on mobile (android)

Post by keram » Tue Apr 08, 2014 1:29 am

Thanks Dave and Neil for your answers,
dave.kilroy wrote:How exactly did it fail on Android? What error message (if any) did you get? Did you try inserting some 'answer' calls in your script to see how far you got and to check out values in variables? Can you confirm whether your paths are OK and did your "MQata" folder get created on your device? Ditto for your .ini file? What platform are you building on? What version of LC? etc etc.
It installs OK, but when opening it shows this message: "Sorry, but there was a problem writing to a .ini file." and no "MQData" folder gets created and no .ini file anywhere o the device.
I did create a button to check the gSFPath, the code:
global gSFPath
on mouseUp
put gSFPath into fld "a"
end mouseUp

it gives correct path in Windows but on Android shows: "/MQdata" only.

I'm building on Win 7 64 bit, with LC Community 6.5.2
runrevneil wrote:Writing to Android will also not work if you do not have "Write External Storage" checked within your Android Standalone Application Setting.
I do have "Allow external Storage" checked.

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

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

Re: how to save data on mobile (android)

Post by Simon » Tue Apr 08, 2014 2:12 am

"mobile" is not in platform()
"android" is :)

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

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: how to save data on mobile (android)

Post by keram » Tue Apr 08, 2014 2:42 am

Hi Simon,

Thanks for your correction! I don't even know where I got that "mobile" platform() from :oops:

Now there is no error message when running the app but there are definitely no data files on the device nor the folder MQdata - it's strange.
When checking gSFPath it shows now:
/data/data/com.yourcompany.yourapp/files/MAdata
Any idea why is that?

keram
Attachments
android native scroller for data grid3.zip
(32.8 KiB) Downloaded 192 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

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

Re: how to save data on mobile (android)

Post by Simon » Tue Apr 08, 2014 2:53 am

I added a btn with

Code: Select all

global gSFPath
on mouseUp
   put url("file:" & gSFPath & "/Selection.ini") into tFIle
   answer tFile
end mouseUp
It is there. It did take a long time (60 secs?) to load.

environment() = "mobile" :)

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

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: how to save data on mobile (android)

Post by keram » Tue Apr 08, 2014 4:29 am

Thanks Simon,
Simon wrote:environment() = "mobile"
Do you mean that I should use the environment() instead pf platform() and put "mobile" under case "mobile"? like this:
switch environment()
case "mobile"
## Android
put specialFolderPath("documents") into gSFPath
break
...
Simon wrote:It did take a long time (60 secs?) to load.
Why is it so?
Is it because there are so many, 640 lines for DG to load?
or is it because something has to be improved in the code?
Is there any way to speed up the loading?
Would using a proper SQL data base speed it up? (I'm not familiar with SQL at this stage).
What device did you test it on?

Did you notice that when selecting some lines and then clicking on the "My selection" button it is not possible to scroll the screen?
Why is it so?

Many questions, but it's the first time I'm creating something for a mobile.

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

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

Re: how to save data on mobile (android)

Post by Simon » Tue Apr 08, 2014 4:53 am

Do you mean that I should use the environment() instead pf platform()
Nope, platform() is ok just change to "android"
Why is it so?
I think it's just the "answer" command is slow. Putting it in a fld is fast.
What device did you test it on?
Kindle Fire HD
...then clicking on the "My selection" button it is not possible to scroll the screen?
Nope, working here as long as there are more selected lines then fit.

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

paul_gr
Posts: 319
Joined: Fri Dec 08, 2006 7:38 pm

Re: how to save data on mobile (android)

Post by paul_gr » Tue Apr 08, 2014 5:25 am

On my Galaxy Note 8.0, App takes about 5 seconds to start up, then very fast response afterwards...

Paul

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: how to save data on mobile (android)

Post by keram » Tue Apr 08, 2014 11:58 am

Hi Paul and Simon,
paul_gr wrote:App takes about 5 seconds to start up
Yes,it's fast to start on my tablet as well - 7 sec. and the "answer" command is also very fast.
Simon wrote:Nope, working here as long as there are more selected lines then fit.
Well, even then it does not work properly in my case. When I go back and forth 3-4 times clicking between "My Categories" and "My Selection" then at some point the scrolling does not work in the "My Categories" view. I then have to restart the app and it works OK.
What do you think it depends on?

Since you have the app installed on your device then I have another question:
I'm using the auto scalling feature ( if the environment = "mobile" then set the fullscreenmode of me to "exactFit") - it's nice.
It scales the font size as well. But on my 8 inch tablet the Labels of the buttons go out of boundaries of the buttons - looks like it does not work properly scaling the width of the buttons. Is it the same on our device? Is there any way to get it work properly automatically?

Thanks.
keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Post Reply