user1057450
user1057450

Reputation:

how to run epub file from assets in android

I created an application by loading epub file in assets. But when I run the application, it displays that application has been stopped unexpectedly. I couldnt find the solution.

Codings are as follows as per the reference: http://www.siegmann.nl/epublib/android

public class EpubActivity extends Activity{

    /** Called when the activity is first created. */
    @Override

    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        AssetManager assetManager = getAssets();

        try{
            InputStream epubInputStream=assetManager.open("book/budget.epub");

            Book book = (new EpubReader()).readEpub(epubInputStream);

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

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

             Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage()

                      .getInputStream());

                  Log.i("epublib", "Coverimage is " + coverImage.getWidth() + " by "

                      + coverImage.getHeight() + " pixels");


                  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);

        }
      }
    }

I don't know where I am going wrong. Added two jar files(sl4j+epub). But I couldn't get the output.

Upvotes: 0

Views: 806

Answers (1)

Villan
Villan

Reputation: 730

You have to add dependencies of sl4j-android like sl4j-api and sl4j-simple to your libs folder and add the libs folder to build path !!

Upvotes: 2

Related Questions