Android 4.0.3, window.openDatabase is not working

I am working on a mobile application because I use html5 / js with Phonegap. I store some data in a local database using window.openDatabase (...).

This works fine with Android 2.x, but when I try to use Android 4.0.3, I catch an 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 this comes from, and how can I solve it? Thanks in advance.

Regards, Vi.

+4
source share
3 answers

According to http://androidforums.com/application-development/103644-why-doesnt-work-javascript-opendatabase-android.html Android had some support for the window.OpenDatabase() method from the very beginning. You might want to see this StackOverflow stream: Android 4.0.1 splits local storage for WebView HTML 5

+2
source

I solved the problem by updating the phonegap library (to version 2.0). I had version 1.9 for .jar, and I always used the old version of the .js file: version 1.4.

I found in some version of DroidGap.java, the WebSettings configuration from WebView does not activate the database. But maybe this is only because I had a very old version for the .js lib.

So now itโ€™s normal.

Thank you for your help.

0
source

I examined this and found that the problem was caused by an attempt to open (create) a database with a large estimated size.

Just start with 5kb (5 * 1024) and then go to 5Mb (5 * 1024 * 1024)

var db = window.openDatabase('mydb', '1.0', 'Test DB', 5 * 1024);

0
source

All Articles