I’m having some problems with android webview, SQLite and my target device. On a physical device, the database is not accessible(see errors at the end).
The setup of the webview:
settings.setJavaScriptEnabled(true);
settings.setDatabaseEnabled(true);
settings.setDatabasePath("/data/data/de.sqlite.webview/databases");
I’m defining the webview in the onCreate method, and setting the update quota twice as high as estimated or bigger than in the HTML5 definition.
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)
{
quotaUpdater.updateQuota(204801); //estimatedSize * 2
}
});
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading( ... )
}
On the Emulator and on Chrome everything works fine, but if I deploy the app to my galaxys2 I’m getting an error: openDatabase is not defined.
The following html-code works in chrome and in the emulated webview:
db = new HKSQL();
db.openSQL();
today = getTodayDate();
createDbTable_LastLogin();
//HKSQL Class
function HkSQL(){
this.query;
this.result;
this.database;
}
HkSQL.prototype.openSQL = function(){
this.database = openDatabase("hkapp","1.0","HKApp","65536");
}
//an example query to create my db
CREATE TABLE IF NOT EXISTS HK_lastlogin (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, datum TEXT NOT NULL)
I have no clue why it doesn’t work on my device. I thought about read and write permissions, but the .db file is already created.
Here are some error messages which, I think, target to the same problem:
Uncaught ReferenceError: openDatabase is not defined
Uncaught TypeError: Object [object DOMWindow] has no method 'openDatabase'
The answer was that both Webviews need to initialized as WebChromeClients with full features.