sinkuri256 / android-scripting

Automatically exported from code.google.com/p/android-scripting
0 stars 0 forks source link

Enable html5 database in webViewShow webView #425

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
In the android browser surfing to an html page as follows:-

<html><head><script>

   var shortName = 'testdb';
   var version = '1.0';
   var displayName = 'My Test Database';
   var maxSize = 65536; // in bytes
   var db = openDatabase(shortName, version, displayName, maxSize);

</script></head><body>hi</body></html>

you will then have access to an sqlite database. calling webViewShow() on an 
html file with the same code in it always returns NULL from the openDatabase 
function.

Searching the web shows that you have to call setDatabaseEnabled and 
setDatabasePath on the webView that is created. See for example:

http://stackoverflow.com/questions/2474475/how-do-i-call-window-opendatabase-fro
m-a-webview-hosted-in-an-android-application

http://www.rohanradio.com/html5-database-api-support-in-an-android-webv

We should enable database for scripts since it is already enabled in the 
standard android browser.

Find attached a minimal html file that opens a database, lets you add simple 
key / value entries and lists all values in the database. This code works in 
the android browser, but not in the webViewShow.

Original issue reported on code.google.com by sihor...@gmail.com on 10 Sep 2010 at 11:46

Attachments:

GoogleCodeExporter commented 9 years ago
Code in those links is as follows:-

WebSettings settings = myWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDatabaseEnabled(true);
String databasePath = this.getApplicationContext().getDir("database", 
Context.MODE_PRIVATE).getPath();
settings.setDatabasePath(databasePath);
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);
    }
});

Original comment by sihor...@gmail.com on 10 Sep 2010 at 11:48

GoogleCodeExporter commented 9 years ago
Do you have any solutions for the webview/webchromeclient ?

Original comment by morri...@gmail.com on 15 May 2012 at 8:33

GoogleCodeExporter commented 9 years ago
Hi,

I tried out the code above but i am experiencing an error "webstorage cannot be 
resolved to a type".

please help.

Original comment by ronjylpe...@gmail.com on 24 Oct 2013 at 2:49