Ali*_*Ali 7 javascript android webview local-storage
我试图从我的本地Web APP使用localstorage,这是WebView初始化部分:
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);
} }
Run Code Online (Sandbox Code Playgroud)
这是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);
}
}
Run Code Online (Sandbox Code Playgroud)
但问题是localStorage总是为null,我检查了权限并创建了一个WebChromeClient
@Override
public void onExceededDatabaseQuota(String url,
String databaseIdentifier,
long currentQuota,
long estimatedSize,
long totalUsedQuota,
WebStorage.QuotaUpdater quotaUpdater)
{
quotaUpdater.updateQuota(estimatedSize * 2);
}
Run Code Online (Sandbox Code Playgroud)
从来没有被称为.谁知道为什么?
谢谢
| 归档时间: |
|
| 查看次数: |
15121 次 |
| 最近记录: |