Javascript 使用webview时,Android上的HTML localStorage为空
我正在尝试从本地web应用程序使用localstorage,以下是WebView初始化部分:Javascript 使用webview时,Android上的HTML localStorage为空,javascript,android,webview,local-storage,Javascript,Android,Webview,Local Storage,我正在尝试从本地web应用程序使用localstorage,以下是WebView初始化部分: static class MyWebView extends WebView { public MyWebView(Context context) { super(context); this.getSettings().setJavaScriptEnabled(true);
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);
} }
下面是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);
}
}
但问题是localStorage总是空的,我已经检查了权限,并创建了一个WebChromeClient
@Override
public void onExceededDatabaseQuota(String url,
String databaseIdentifier,
long currentQuota,
long estimatedSize,
long totalUsedQuota,
WebStorage.QuotaUpdater quotaUpdater)
{
quotaUpdater.updateQuota(estimatedSize * 2);
}
从来没有人打过电话。
有人知道为什么吗
谢谢您是否已尝试根据以下答案启用设置:是否已在WebView上设置自定义WebRomeClient?是的,我已使用WebView.setWebChromeClient…可能重复