In an Android application I'm trying to display an EPUB book through WebView. For navigate the book I'm using EPUBJS, and Pure Drawer for some visual effects. When I run my application in devices witch use Android KitKat(4.4) version or above this works fine, but if I try below versions like Jelly Beans(4.3). Some features of Epub.js doesn't work, for example Book.prev, Book.next, Book.goto(url) and Book.renderTo() while other features like Book.getToc() and Book.getMetadata() still work fine, and I can get all books chapters.
I put all the code in an javascript file as follow
function init_js_code(url){
var Book = ePub(url, { restore: true});
Book.getMetadata().then(function(meta){
document.title = meta.bookTitle;
});
$( "#next" ).click(function() {
Book.nextPage();
});
$( "#prev" ).click(function() {
Book.prevPage();
});
Book.getToc().then(function(toc){
var $select = document.getElementById("toc"),
$docfrag = document.createDocumentFragment();
var cList = $('ul.nav-primary');
toc.forEach(function(chapter) {
// logic to create a menu
});
});
Book.ready.all.then(function(){
document.getElementById("loader").style.display = "none";
});
Book.renderTo("area");
In html file there is just a call to this function
<head>
<script src="jquery.js"></script>
...
</head>
<body>
...
<script>
function getPDFURL(){
...
}
var url = 'http://' + getPDFURL() + '.epub';
init_js_code(url);
</script>
</body>
The html code is rendered in activity this way
final WebView webView = (WebView) findViewById(R.id.webView1);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
settings.setAllowUniversalAccessFromFileURLs(true);
}
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
if(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.HONEYCOMB) {
settings.setDisplayZoomControls(false);
}
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
..
}
});
webView.loadUrl("file:///android_asset/.../index.html?url="+material_url);
Although what cold be the problem, some Javascript functions are blocked in this devices? There are any another way to it?