1. Check out our companion app, Forums for Android! Download from Google Play

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

Discussion in 'Application Development' started by etaranov, Jun 18, 2010.

  1. etaranov

    etaranov New Member
    Thread Starter

    Jun 18, 2010
    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?



  2. markb

    markb Well-Known Member

    Sep 14, 2009
    Software Developer (Java, C, Web, Unix)
    Birmingham, UK
    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:

    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?

  3. Pratush

    Pratush Member

    Sep 15, 2010
    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.
    Please help
  4. Pratush

    Pratush Member

    Sep 15, 2010
    I have already added following code in my activity class:
    but still not working..
    I am using os version 2.3.3.
    Please Help... :(
  5. hansschmucker

    hansschmucker Well-Known Member

    Apr 22, 2011
    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
  6. FireArms

    FireArms New Member

    Oct 19, 2010
    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

Share This Page