5

How is it possible to access Web SQL database created in PhoneGap app from native code in Android?

I have a local notification plugin set up and what I want to achieve is fetch user setting from web database to set a correct interval for my alarm.

Makoto
  • 104,088
  • 27
  • 192
  • 230
micadelli
  • 2,482
  • 6
  • 26
  • 38

2 Answers2

1

I have modified the Cordova(https://github.com/Coder-Nasir/incubator-cordova-android) in such a way that it will create the database in Android's Default location which is /data/data/package-name/databases/

By just this simple command

window.openDatabase("something", "1.0", "PhoneGap Demo", 0);

You will get your desired something.db in the above mentioned location..

coderslay
  • 13,960
  • 31
  • 73
  • 121
  • the code changes you've made make sense... as long as google won't change the path. But the main problem still is that I have you open database in my android native code, plugin. The code example you gave is for javascript side. By the way, where does phonegap normally deploy the database on device. I cannot find it when debugging. – micadelli Mar 16 '12 at 10:51
  • Yes so its easy to open the database with the native Code.Since it is in the default path right?... And Phonegap uses webview database and stores it in /data/data/packagename/app_database/file__0/00000000000000001.db – coderslay Mar 16 '12 at 10:57
  • hmm.. somehow in eclipse when i try to look for my database file in DDMS i can't find it anywhere. The whole data folder is empty. This is using the phonegap-1.3... do you know how to find it? – micadelli Mar 16 '12 at 15:50
  • Go to DDMS--->File Explore--->data----->data---->Packagename---->app_database---->file__0 – coderslay Mar 16 '12 at 17:24
  • that is exactly where I tried to look it for. As I earlier stated, the whole data folder is empty, although my database is successfully created in my script. Using HTC Wildfire S for testing. I also can fetch things from my database but still can't find it anywhere. – micadelli Mar 16 '12 at 21:53
  • @Coder_sLaY: using this library will i be able to acces my android app database from /data/data/appPackage/databases/ ?? Or will it createa like cordova or basic javascript code its own db & the ugly - /file__0/00000000000000001.db ?? – pulancheck1988 Oct 22 '12 at 17:59
  • @pulancheck1988 you will be able to get from android default database location `./databases/` with a database name you prefer – coderslay Oct 25 '12 at 03:24
  • i know i am too late but this link will help someone else .... http://stackoverflow.com/a/14974140/676755 – chhameed Sep 17 '13 at 12:39
-1

Easiest solution seems to be to create a shared preference plugin, should work well with small and simple data.

micadelli
  • 2,482
  • 6
  • 26
  • 38