How To Render A Epub File In A Native Android App?
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 pdfRenderer which disp
Solution 1:
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:
- Implement the NavigatorEventListener in your class.
Initialize Navigator like the following snippet:
privatevoidinit() { 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:
@OverridepublicvoidnavigationPerformed(NavigationEvent navigationEvent) { if (navigationEvent.isResourceChanged()) { intcurrentSpinePos= navigationEvent.getCurrentSpinePos(); displayPage(navigationEvent.getCurrentResource(), currentSpinePos);navigationEvent.getCurrentResource().toString()); } }
Add displayPage method to show epub:
privatevoiddisplayPage(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.
Post a Comment for "How To Render A Epub File In A Native Android App?"