[TIMOB-5088] Android: webView does not support openDatabase
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-07-30T17:20:02.000+0000 |
Affected Version/s | Release 1.7.2, Release 2.0.2, Release 3.0.0, Release 3.0.2, Release 3.1.0 |
Fix Version/s | 2013 Sprint 16, 2013 Sprint 16 API, Release 3.2.0 |
Components | Android |
Labels | hard_to_verify, parity |
Reporter | Jon Alter |
Assignee | Hieu Pham |
Created | 2011-08-23T14:38:04.000+0000 |
Updated | 2013-10-24T00:17:38.000+0000 |
Description
openDatabase does not work in a webView but it does in the Android browser.
Step 1: create a file called test.html
Step 2: host it
Step 3: run the code below (changing the url to point to test.html)
Step 4: notice that the database is not created
Step 5: use the android browser and go to the same file
Step 6: notice that the database is created successfully
var win = Ti.UI.createWindow();
var webView = Ti.UI.createWebView({
url: "http://192.168.1.137/~jalter/test/test.html"
});
win.add(webView);
win.open();
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function setupDatabase() {
var result = document.getElementById('result');
var db;
db = openDatabase('tweets', '1.0', 'db of tweets', 2 * 1024 * 1024);
if(db){
result.innerHTML = '<li>DB created successfully</li>';
}else{
result.innerHTML = '<li>DB failed to be created</li>';
}
}
</script>
</head>
<body onload="setupDatabase()">
<div id='result'>Nothing yet...</div>
</body>
</html>
Associated Helpdesk Ticket
http://appc.me/c/APP-323498Another customer having the same issue
I need to use web SQL in a Titanium web View. I've used the following code snippet to test the functionality. This code works fine on iPhone, but it fails on Android. Can you please provide assistance in this regard.
var db = openDatabase('mydb', '1.0', 'my first database', 1024);
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS foo (id unique, text)');
tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "ABCD")');
});
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM foo', [], function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
$("#val1").text("Value : "+results.rows.item(i).text);
}
});
});
Here is what needs to happen. I reviewed the source on https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/ti/modules/titanium/ui/widget/webview/TiUIWebView.java and it looks like you are not enabling the database. That would require the addition of settings.setDatabaseEnabled(true); in TiUIWebView.
[~dthorp] This is not a feature, it's a bug because it's inconsistent with iOS where this works fine (Haven't tried BB yet). This brakes the promise of Titanium and therefore should be a bug (and IMO of course should be addressed immediately.) :)
master PR: https://github.com/appcelerator/titanium_mobile/pull/4507
Verified the fix. Database is created successfully. Closing. Environment: Appcel Studio : 3.2.0.201310230601 Ti SDK : 3.2.0.v20131022171645 Mac OSX : 10.8.5 CLI - 3.2.0 with hash 72f7426b4ee6c2d2883c666d5b7e03906a16012f Device: Samsung Galaxy S4 running android 4.2.2