6
Tôi cố gắng để sử dụng localStorage từ web địa phương của tôi APP, đây là phần WebView khởi:HTML localStorage là null trên Android khi sử dụng 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);
} }
và đây là ứng dụng thử nghiệm trên 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);
}
}
nhưng vấn đề là localStorage luôn là null, tôi đã kiểm tra các điều khoản và tạo một WebChromeClient với
@Override
public void onExceededDatabaseQuota(String url,
String databaseIdentifier,
long currentQuota,
long estimatedSize,
long totalUsedQuota,
WebStorage.QuotaUpdater quotaUpdater)
{
quotaUpdater.updateQuota(estimatedSize * 2);
}
không bao giờ được gọi. Bất cứ ai cũng biết tại sao?
Cảm ơn
Bạn đã thiết lập WebCromeClient tùy chỉnh của bạn trên WebView? – Flo
có, tôi đã sử dụng webView.setWebChromeClient ... – Ali