damonkohler / sl4a

SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device.
Apache License 2.0
2.43k stars 800 forks source link

Enable html5 database in webViewShow webView #212

Open damonkohler opened 9 years ago

damonkohler commented 9 years ago

From @GoogleCodeExporter on May 31, 2015 11:27

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:

Copied from original issue: damonkohler/android-scripting#425

damonkohler commented 9 years ago

From @GoogleCodeExporter on May 31, 2015 11:27

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

damonkohler commented 9 years ago

From @GoogleCodeExporter on May 31, 2015 11:27

Do you have any solutions for the webview/webchromeclient ?

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

damonkohler commented 9 years ago

From @GoogleCodeExporter on May 31, 2015 11:27

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