Android 4.0.3, window.openDatabase doesn't work
-
27-06-2021 - |
Pregunta
I'm working on a mobile app, for that I use html5/js with Phonegap. I store some data in a local database with window.openDatabase(...).
That's work fine with Android 2.x But when I try with Android 4.0.3, I catch the following error :
D/CordovaLog(698): Uncaught TypeError: Object [object DOMWindow] has no method 'openDatabase'
My code is :
if (!window.openDatabase)
alert("Error: can't open local database");
if (!localStorage)
alert("Error: localstorage not usable");
var db = window.openDatabase("Database", "1.0", "DatabaseName", 200000);
Do you have an idea where that come from and how I can resolve it ? Thanks in advance.
Kind regards, Vi.
Solución
According to http://androidforums.com/application-development/103644-why-doesnt-work-javascript-opendatabase-android.html, Android has had iffy support for window.OpenDatabase()
method since the start. You may want to see this StackOverflow thread: Android 4.0.1 breaks WebView HTML 5 local storage?
Otros consejos
I resolved my problem by updating the phonegap lib (to version 2.0). I had the version 1.9 for the .jar and I used always an old version for the .js file : version 1.4.
I found in some version of DroidGap.java, the configuration of WebSettings from WebView don't activate Database. But maybe it's just because I had a very old version for .js lib.
So now, it seems to be ok.
Thanks for your help.
I investigated this and found that the issue is caused by trying to open (create) the database with a large estimated size.
Just start with 5kb (5*1024) and then move to 5Mb (5*1024*1024)
var db = window.openDatabase('mydb', '1.0', 'Test DB', 5 * 1024);