• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Why doesn't work javascript openDatabase() on Android?

etaranov

Lurker
Jun 18, 2010
1
0
Hi all,
I created simple javascript that uses local web db to store data.
My code is works on iPnohe and Chrome (desktop browser), but not working on Android.
I run The HTML5 test - How well does your browser support HTML5? tests and see that it should support html5 web db.
It has openDatabase() function but it failed when i trying to call openDatabase() to create database.
Why javascript function openDatabase doesn't work on Android?
Can anyone help with that?

Thanks
 
What version of the Android OS are you using?
From this page it looks like HTML5 DB support was introduced in version 2.0

Android 2.0 Platform Highlights | Android Developers

I found an example HTML5 DB app here:
http://webkit.org/misc/DatabaseExample.html

I tried it on my Nexus One (running 2.2 beta) and it seems to work.
(Well, it does something. I can't really say if it's working properly.)

I tried the html5test.com website you referred to.

My Nexus One browser scored 176 out of 300.
I got a tick for Session Storage, Local Storage and Web SQL Database.
I got a cross for IndexedDB.

Did you get the same result?

Mark
 
Upvote 0
I have the same problem with the javascript database.
I am opening Html page form resource via WebView.
When window.opendatabse function calls it returns null value.
It is working fine in iphone wrapper app. But not on android.
var db= null;
var dbSize = 5 * 1024;
alert("db opening");
db = window.openDatabase("app", "1.0", "app manager", dbSize);
alert(db);// shows null

Please help
 
Upvote 0
I have already added following code in my activity class:
WebView wv = (WebView) findViewById(R.id.webView1);
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDatabaseEnabled(true);
settings.setAppCacheEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
String databasePath = this.getApplicationContext().getDir("app",
Context.MODE_PRIVATE).getPath();
settings.setDatabasePath(databasePath);

but still not working..
I am using os version 2.3.3.
Please Help... :(
 
Upvote 0
The only thing that really comes to mind is: Is the code executed in the right order? Or do you just execute the JS onload? Maybe you should implement your own JS init function and call it from Java once everything is set. Aside from that setDatabasePath may not apply immediately: "This will update WebCore when the Sync runs in the C++ side."

Could you just try executing your JS code with a really big delay? Say 10000ms?


I'm really just guessing here.

P.S. Google returned this:
Issue 425 - android-scripting - Enable html5 database in webViewShow webView - Scripting Layer for Android brings scripting languages to Android. - Google Project Hosting
It's about another issue, but comment 1 contains sample code :)

P.P.S Found some other links that basically state the same problem: You HAVE to implement onExceededDatabaseQuota
 
Upvote 0
I was using following java script code to create database:
var database = window.openDatabase("total", "", "main total", 1024*1024);

Some how database object in HTML 5 was always coming as NULL both in emulator and device. Same HTML 5 code was working properly in Crome browser. In the end, I drilled down to quotaUpdater.updateQuota() method, I tried various quota sizes but at the end "estimatedSize * 2" worked for me which is mentioned in above code sample.

For more information you can look at link: Technology Freak: How to run HTML5 app from Android app? Android + WebView + HTML5 + Java Script + Web DB
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones