I am trying to use localstorage from my local web APP, here is the WebView initialization part:
static class MyWebView extends WebView
{
public MyWebView(Context context)
{
super(context);
this.getSettings().setJavaScriptEnabled(true);
//enable support for DOM Storage and Database
this.getSettings().setDatabaseEnabled(true);
this.getSettings().setDomStorageEnabled(true);
String databasePath = context.getDir("database", Context.MODE_PRIVATE).getPath();
this.getSettings().setDatabasePath(databasePath);
this.setVerticalScrollbarOverlay(true);
} }
and Here is the test app on JavaScript:
function testStorage()
{
var storage = window.localStorage;
if (storage) {
try {
storage.setItem("name", "Hello World!"); //saves to the database, “key”, “value”
} catch (e) {
alert(e.message); //data wasn’t successfully saved due to quota exceed so throw an error
}
document.write(storage.getItem("name")); //Hello World!
storage.removeItem('name');
}
else {
alert('Your browser does not support HTML5 localStorage. Because Storage is' + storage);
}
}
but the problem is that the localStorage is always null, I have checked the permissions and created a WebChromeClient with
@Override
public void onExceededDatabaseQuota(String url,
String databaseIdentifier,
long currentQuota,
long estimatedSize,
long totalUsedQuota,
WebStorage.QuotaUpdater quotaUpdater)
{
quotaUpdater.updateQuota(estimatedSize * 2);
}
which never gets called. Anyone knows why?
Thanks
I am trying to use localstorage from my local web APP, here is the WebView initialization part:
static class MyWebView extends WebView
{
public MyWebView(Context context)
{
super(context);
this.getSettings().setJavaScriptEnabled(true);
//enable support for DOM Storage and Database
this.getSettings().setDatabaseEnabled(true);
this.getSettings().setDomStorageEnabled(true);
String databasePath = context.getDir("database", Context.MODE_PRIVATE).getPath();
this.getSettings().setDatabasePath(databasePath);
this.setVerticalScrollbarOverlay(true);
} }
and Here is the test app on JavaScript:
function testStorage()
{
var storage = window.localStorage;
if (storage) {
try {
storage.setItem("name", "Hello World!"); //saves to the database, “key”, “value”
} catch (e) {
alert(e.message); //data wasn’t successfully saved due to quota exceed so throw an error
}
document.write(storage.getItem("name")); //Hello World!
storage.removeItem('name');
}
else {
alert('Your browser does not support HTML5 localStorage. Because Storage is' + storage);
}
}
but the problem is that the localStorage is always null, I have checked the permissions and created a WebChromeClient with
@Override
public void onExceededDatabaseQuota(String url,
String databaseIdentifier,
long currentQuota,
long estimatedSize,
long totalUsedQuota,
WebStorage.QuotaUpdater quotaUpdater)
{
quotaUpdater.updateQuota(estimatedSize * 2);
}
which never gets called. Anyone knows why?
Thanks
Share Improve this question edited Jan 2, 2012 at 12:59 Flo 27.5k16 gold badges91 silver badges126 bronze badges asked Jan 2, 2012 at 12:46 AliAli 1411 gold badge1 silver badge4 bronze badges 3- Have you set your custom WebCromeClient on the WebView? – Flo Commented Jan 2, 2012 at 13:00
- yes, I have using webView.setWebChromeClient ... – Ali Commented Jan 2, 2012 at 13:02
- Possible duplicate of Android webview & localStorage – Nateowami Commented May 28, 2019 at 20:59
1 Answer
Reset to default 20Have you tried just enabling the setting as per this answer : https://stackoverflow.com/a/5934650/85472