I am trying to make a android app that would render a .epub file and display its content in an android layout.
I did a similar app for displaying pdf\'s using pdfRendere
You can learn from PageTurner Reader and epub3reader
For a simple way you can use WebView with Navigator and NavigatorEventListener from nl.siegmann.epublib.browsersupport package. Though WebView is not a 'native' one.
Here the steps:
Initialize Navigator like the following snippet:
private void init() {
mNavigator = new Navigator();
mNavigator.addNavigationEventListener(this);
mNavigator.gotoBook(book, this); // book is from your loaded InputStream book
mNavigator.gotoFirstSpineSection(this);
}
In your implemented NavigationPerformed add like this:
@Override public void navigationPerformed(NavigationEvent navigationEvent) {
if (navigationEvent.isResourceChanged()) {
int currentSpinePos = navigationEvent.getCurrentSpinePos();
displayPage(navigationEvent.getCurrentResource(), currentSpinePos);navigationEvent.getCurrentResource().toString());
}
}
Add displayPage method to show epub:
private void displayPage(Resource resource, int sectionPos) {
if (resource == null) {
return;
}
try {
mWebView.loadDataWithBaseURL("file:///android_asset/data/", data, "text/html", "UTF-8", null);
} catch (Exception e) {
Log.d(TAG, "When reading resource "
+ resource.getId()
+ "("
+ resource.getHref()
+ ") :"
+ e.getMessage(), e);
}
}
Finish.