GAMA
GAMA

Reputation: 5996

Working with ePub files in android

I referred this siegmann android tutorial and successfully logged the Title, Author name and Table of contents.

Now I read that the whole book can be viewed in WebView.

But I don't find any tutorial for Dispalying an ePub file.

When it comes to creating an ePub file, I found this from SO But I'm unable to implement it as I don't have any idea about main.xml.

Kindly suggest any tutorial to create and display an ePub file.

For creating ePub, I tried to refer this siegmann eg but I'm not able to understand it properly.

Do I need to provide .html for each chapter and .css in order to create an ePub file?

I know I'm little unclear in this qustion as I'm absolute beginner when it comes to working with ePub, so any suggestions/help appreciated.

Upvotes: 4

Views: 2923

Answers (2)

Villan
Villan

Reputation: 730

You can also spine the epub content with the help of

        Spine spine = book.getSpine(); 
        List<SpineReference> spineList = spine.getSpineReferences() ;
        int count = spineList.size();
        StringBuilder string = new StringBuilder();
        for (int i = 0; count > i; i++) {
            Resource res = spine.getResource(i);
            try {
                InputStream is = res.getInputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                try {
                    while ((line = reader.readLine()) != null) {
                        linez =   string.append(line + "\n").toString();
                        System.err.println("res media"+res.getMediaType());
                        htmlTextStr = Html.fromHtml(linez).toString();
                        Log.e("Html content.",htmlTextStr);
                        speak(htmlTextStr);
                    }
                } catch (IOException e) {e.printStackTrace();}

                //do something with stream
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        webview.getSettings().setAllowFileAccess(true);
        webview.getSettings().setBuiltInZoomControls(true);
        webview.getSettings().setJavaScriptEnabled(true);

        webview.loadDataWithBaseURL("file:///android_asset/", linez, "application/xhtml+xml", "UTF-8", null);

Upvotes: 0

Krunal
Krunal

Reputation: 6490

Try this in logTableOfContents()

while ((line = r.readLine()) != null) {

line1 = line1.concat(Html.fromHtml(line).toString());

}

finalstr = finalstr.concat("\n").concat(line1);

Upvotes: 2

Related Questions