Databases, localstorage and interaction with my code

My phonegap app for android uses coordinate geometry to create and manipulate rectilinear coordinates and compute various values. I had a lengthy post prepared with much more code than shown here but decided that could come later if necessary. My app puts the db in localstorage (LS). I use a free app called “wifi file transfer” to move files between my computer and device and it does essentially what usb debugging does. I want a user to be able to import their own db and use it with my code without my intervention. Dallrich and George weighed in on a similar question of mine a while back but I couldn’t capitalize. I am able to do it here on the desktop because I can stringify the db with a separate program, add this file to the folder containing the nsx and into the manifest and then import it with the following code:

Function userresponse(ans)
If ans = vbOK Then 
localStorage.removeItem("data02")  
  coord=Array
  localStorage.clear()  ' wipes out what exists in LS
  req = ReadFile("sdon.txt")    'sdon.txt is a stringified file
  If req.status = 200 Or req.status = 0 Then
coord = JSON.parse(req.responseText)
  localStorage.data02=coord
MsgBox "The new database has now been imported into LocalStorage"
End If
Else
  MsgBox "No action taken"
End If
End Function

This is an example of what LS looks like with some data:

[“1,1000,1000,pt1\n”,“2,1027.69920,1030.22837,pt2\n”,“3,1038.56960,1070.79725,pt3\n”,“4,999.93257,1081.15002,pt4\n”,“5,1034.91736,1100.54240,pt5\n”,“6,1082.14682,1126.72212,pt6\n”,“7,1028.14682,1126.72212,pt7\n”,“8,1028.14682,1141.72212,pt8\n”,“9,958.14682,1141.72212,pt9\n”,“10,941.18608,1080.52912,pt10\n”] all neat and stringified

It seems that the bottom line is getting a stringified file into LS on the device. I can provide a user with the stringify progam to prepare the file but he would need to know where on the device to put it. Currently the stringified file on mine is in storage/emulated/0 but the code does not interact with it. Does anyone know where LS is found on an android device? Does the device have to be rooted? I have looked at most of the suspect folders without success. The Chrome debugger shows what is in LS while using the desktop browser but that doesn’t help other users. This issue may be unsolvable with my approach but perhaps there is another db method I could use, including sqlite, but that has to go somewhere too. It will have to be simple, though, for my 84 year old brain. Thanks in advance. In the meantime I will keep google busy.

You will probably need to use PhoneGap plugin to read the file.

The ReadFile commands which can be run in a browser are best for reading data in the browser sandbox. After all, you wouldn’t want a web page you open on the net to be able to access any file you have on the device.

Alternatively, find another way to get the data to the device which doesn’t involve the file system.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.