Android webview: display local HTML and XML for DB in assest folder



I created index.html file that connected to pasta.xml and show all data in pasta.xml in windows explorer PC.


When I import to webview at android, in simulator is OK, and simulator display images or data successfully


But when I export apk and install in my Tablet, it doesn't display image or data and only display empty HTML


I think my JavaScript in HTML has problem and can't find pasta.xml in assets folder.


what's problem?


JavaScript code that included in index.html and called pasta.xml (pasta.xml is a database for HTML file and coped in assets folder)



<script>
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
}
else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","pasta.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;


var x=xmlDoc.getElementsByTagName("RECIPES");
for (i=0;i<x.length;i++) {
document.write('<a href="single.html?id='+i+'">');
document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write('</a>');
}

</script>


MainActivity.java



String file_path = "file:///android_asset/index.html";

WebView webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl(file_path);

No comments:

Post a Comment