Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old June 18th, 2010, 04:49 AM   #1 (permalink)
New Member
 
Join Date: Jun 2010
Posts: 1
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default Why doesn't work javascript openDatabase() on Android?

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

etaranov is offline  
Reply With Quote
Sponsors
Old June 18th, 2010, 11:25 AM   #2 (permalink)
Member
 
Join Date: Sep 2009
Location: Birmingham, UK
Posts: 148
 
Device(s): G1 (Developer model), HTC Tattoo, Nexus One.
Thanks: 1
Thanked 26 Times in 22 Posts
Default

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
markb is offline  
Reply With Quote
Old June 20th, 2011, 04:42 AM   #3 (permalink)
New Member
 
Join Date: Sep 2010
Posts: 6
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Quote:
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
Pratush is offline  
Reply With Quote
Old June 20th, 2011, 06:21 AM   #4 (permalink)
New Member
 
Join Date: Sep 2010
Posts: 6
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Angry

I have already added following code in my activity class:
Quote:
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...
Pratush is offline  
Last edited by Pratush; June 20th, 2011 at 07:01 AM.
Reply With Quote
Old June 20th, 2011, 08:29 AM   #5 (permalink)
Member
 
hansschmucker's Avatar
 
Join Date: Apr 2011
Posts: 257
 
Device(s):
Thanks: 3
Thanked 40 Times in 36 Posts
Default

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
hansschmucker is offline  
Reply With Quote
Old July 12th, 2011, 07:49 AM   #6 (permalink)
New Member
 
Join Date: Oct 2010
Posts: 1
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
FireArms is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
No Java or Javascript on Android Browsers alanbcohen Android Applications 14 November 4th, 2011 03:42 PM
Does Android support web browser javascript extension? superyuan Application Development 4 January 11th, 2011 06:46 PM
Javascript message (but it's already enabled) - what's up!? Redflea Motorola Droid 3 December 23rd, 2009 11:53 AM



All times are GMT -5. The time now is 11:29 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo