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

Apps webdatabase not working with Webview Javascript

Pratush

Lurker
I have the problem with 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 as well as chrome database. 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
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... :(
 
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:
http://code.google.com/p/android-scripting/issues/detail?id=425
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
 
Firstly thanks hansschmucker for the quick reply.

Can you please give me some sample code for how to open database at before load the html code form Java class. Second is yes I am calling the openDB function at the time of onload html function.
Third what do you mean by the delay of Executing the Js. Do I need to put some wait in the JavaScript function?

Please reply... thanks in Advance.
 
Forget about the delay, I was probably barking up the wrong tree there: just try implementing onExceededDatabaseQuota.

Code:
myWebView.setWebChromeClient(new WebChromeClient() {
	@Override
    public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
        long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
        quotaUpdater.updateQuota(estimatedSize * 2);
    }
});

Note that I'm not currently developing for Android, so this is still just guessing...
 
Glad it is working for you Pratush, and welcome to AF!

Also, just FYI, I moved your thread to the Application development forum.
 
Back
Top Bottom