Ho una semplice pagina di test html5 che utilizza LocalStorage per visualizzare/salvare/visualizzare nuovamente un dato.Android 4.0.1 interrompe la memorizzazione locale HTML 5 di WebView?
Questo codice funziona perfettamente in 2.3.x Android, ma tronchi un'eccezione in 4.0.1 on line 18 della html che è la chiamata Frist localStorage.getItem()
ed a questo punto il JS si ferma.
Eccezione: Uncaught Error: SECURITY_ERR: DOM Exception 18 at /data/data/my.app.name/app_htmlData:18
Ho anche provato a impostare il percorso del database su getCacheDir()
con lo stesso risultato.
String htmlContent = "HTML content listed below";
File sharedDir = getActivity().getDir("htmlData", Context.MODE_PRIVATE);
WebView browser = (WebView)v.findViewById(R.id.wvBrowser);
browser.setWebChromeClient(new WebChromeClient(){
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
quotaUpdater.updateQuota(estimatedSize * 2);
}
});
browser.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url){
view.loadUrl("javascript:doTest()");
});
browser.getSettings().setDatabaseEnabled(true);
browser.getSettings().setDatabasePath(sharedDir.getPath());
browser.getSettings().setDomStorageEnabled(true);
browser.loadDataWithBaseURL(mSharedDir.getPath(),
htmlContent,
"text/html",
"utf-8",
null);
Il codice HTML che la pagina viene eseguito il rendering è la seguente:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Simple localStorage test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
function doTest() {
$('#stuff').append('<p>reading</p>');
var item = read();
$('#stuff').append('<p>writing</p>');
localStorage['bar'] = new Date().toUTCString();
$('#stuff').append('<p> </p><p>reading again</p>');
read();
}
function read() {
var item = localStorage.getItem('bar');
if (item == null || (item == undefined)) {
item = '';
}
$('#stuff').append('<p> item: ' + item + '</p>');
return item;
}
</script>
</head>
<body>
<p>-Simple localStorage test-</p>
<div id="stuff"></div>
</body>
</html>
sorgente disponibile here
Qual è l'eccezione che viene registrata? – CommonsWare
Siamo spiacenti, sarebbe utile - aggiunto alla domanda – MrChaz
È strano. Se hai un progetto di esempio completo che potresti impacchettare e caricare da qualche parte, mi piacerebbe dargli un'occhiata. – CommonsWare