The same problem I encountered, but after a long thorough reading of the phonegap-cordova library, I found that it lacked the flexibility to choose a path.
The reason may be due to the cross-platform restriction, the library bound you to using the default application path, so on another platform the library could easily get the file.
but what!! there is a trick to achieve the goal ....
function onDeviceReady() { var db = window.openDatabase("test", "1.0", "Test DB", 1000000); }
in fact, when JavaScript calls the openDatabase () function, it does the following
- add '/ data / data / <package_name_of_your_app> /' in front of db_name
- and add '. db ' after db_name
ie: in the above case would be:
/ data / data / <package_name_of_your_app> /test.db
therefore the trick goes here;
function onDeviceReady() { var db = window.openDatabase("../../../../mnt/sdcard/test", "1.0", "Test DB", 1000000); }
- add '../../../../mnt/sdcard/' before the name db_name, do not add the extension, since the library adds `.db ', if you add any extension, then your db file will be db_name . (yourextension) .db
now what! it will be;
- add '/ data / data / <package_name_of_your_app> /' in front of db_name
- and add '. db ' after db_name
- it will take your name db _ .. / .. / .. / .. / mnt / sdcard / test '
therefore the result will be:
/ data / data / <package_name_of_your_app> /../../../../mnt/SDCard/test.db
so it will return to the root of your mobile phone and then / mnt / sdcard
source share