Shows nothing on android screen using epub file

I am using this epub file and the code I am using is

public class MainActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    AssetManager assetManager = getAssets();

    try {
      // find InputStream for book
      InputStream epubInputStream = assetManager.open("widget.epub");
      System.err.println("epubInputStream>>"+epubInputStream);
      // Load Book from inputStream
      Book book = (new EpubReader()).readEpub(epubInputStream);

      // Log the book authors
      Log.i("epublib", "author(s): " + book.getMetadata().getAuthors());

      // Log the book title
      Log.i("epublib", "title: " + book.getTitle());

      // Log the book coverimage property
      Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage().getInputStream());
     Log.i("epublib", "Coverimage is " + coverImage.getWidth() + " by " + coverImage.getHeight() + " pixels");

      // Log the tale of contents
      logTableOfContents(book.getTableOfContents().getTocReferences(), 0);
    } catch (IOException e) {
      Log.e("epublib", e.getMessage());
    }
  }

private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
    if (tocReferences == null) {
      return;
    }
    for (TOCReference tocReference : tocReferences) {
      StringBuilder tocString = new StringBuilder();
      for (int i = 0; i < depth; i++) {
        tocString.append("\t");
      }
      tocString.append(tocReference.getTitle());
      Log.i("epublib", tocString.toString());

      logTableOfContents(tocReference.getChildren(), depth + 1);
    }
  }

      

}

My xml is ::

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="@string/hello_world" />
</RelativeLayout>

      

My Logcat displays every log without error

02-04 15:12:46.839: D/dalvikvm(26799): WAIT_FOR_CONCURRENT_GC blocked 6ms
02-04 15:12:46.849: I/epublib(26799): author(s): [Starr, E.L.]
02-04 15:12:46.849: I/epublib(26799): title: EPUB Widgets: Figure Gallery
02-04 15:12:46.879: D/dalvikvm(26799): GC_FOR_ALLOC freed 152K, 7% free 8209K/8788K, paused 24ms, total 24ms
02-04 15:12:46.889: I/dalvikvm-heap(26799): Grow heap (frag case) to 11.828MB for 3813392-byte allocation
02-04 15:12:46.919: D/dalvikvm(26799): GC_FOR_ALLOC freed <1K, 5% free 11933K/12516K, paused 24ms, total 24ms
02-04 15:12:46.929: D/dalvikvm(26799): GC_CONCURRENT freed <1K, 5% free 11932K/12516K, paused 3ms+2ms, total 18ms
02-04 15:12:46.979: I/epublib(26799): Coverimage is 1024 by 931 pixels
02-04 15:12:46.979: I/epublib(26799): Phases of the Moon
02-04 15:12:47.019: D/libEGL(26799): loaded /system/lib/egl/libEGL_tegra.so
02-04 15:12:47.059: D/libEGL(26799): loaded /system/lib/egl/libGLESv1_CM_tegra.so
02-04 15:12:47.059: D/libEGL(26799): loaded /system/lib/egl/libGLESv2_tegra.so
02-04 15:12:47.079: D/OpenGLRenderer(26799): Enabling debug mode 0

      

I can only display HelloWorld

on scree, not epub content !! How can I display epub content?

+3


source to share


1 answer


change the logtableofcontents method with



 private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
    if (tocReferences == null) {

        return;
    }

    for (TOCReference tocReference : tocReferences) {
        StringBuilder tocString = new StringBuilder();
         for (int i = 0; i < depth; i++) {
         tocString.append("\t");
         }
         tocString.append(tocReference.getTitle());
         Log.i("TOC", tocString.toString());

        try {
            InputStream is = tocReference.getResource().getInputStream();
            BufferedReader r = new BufferedReader(new InputStreamReader(is));

            while ((line = r.readLine()) != null) {
                // line1 = Html.fromHtml(line).toString();
                Log.v("line" + i, Html.fromHtml(line).toString());
                // line1 = (tocString.append(Html.fromHtml(line).toString()+
                // "\n")).toString();
                line1 = line1.concat(Html.fromHtml(line).toString());
            }
            finalstr = finalstr.concat("\n").concat(line1);
            // Log.v("Content " + i, finalstr);
            i++;
        } catch (IOException e) {

        }

        logTableOfContents(tocReference.getChildren(), depth + 1);
    }

    webview.loadDataWithBaseURL("", finalstr, "text/html", "UTF-8", "");
}

      

+2


source







All Articles