如何用skyepub读取epub文件?

时间:2014-03-26 10:53:12

标签: java android

我想使用skyepub SDK来阅读我的epub书籍。 但是,当我想阅读一个epub时,我不断得到一个空白的屏幕:

03-26 10:46:11.458: I/System.out(1848): GET '/Alexandre Dumas - Les Trois Mousquetaires/META-INF/container.xml' 
03-26 10:46:11.458: I/System.out(1848):   HDR: 'user-agent' = 'Dalvik/1.6.0 (Linux; U; Android 4.4.2; Nexus 7 - 4.4.2 - API 19 - 800x1280 Build/KOT49H)'
03-26 10:46:11.458: I/System.out(1848):   HDR: 'host' = 'localhost:51005'
03-26 10:46:11.458: I/System.out(1848):   HDR: 'accept-encoding' = 'gzip'
03-26 10:46:11.458: I/System.out(1848):   HDR: 'connection' = 'Keep-Alive'
03-26 10:46:12.238: W/AwContents(1848): nativeOnDraw failed; clearing to background color.
03-26 10:46:12.242: W/AwContents(1848): nativeOnDraw failed; clearing to background color.
03-26 10:46:12.258: W/AwContents(1848): nativeOnDraw failed; clearing to background color.

我解压缩了我想在Application Android目录中阅读的每本书,所以我猜它与unziping无关。

以下是代码:http://pastebin.com/BuC9DJsf

解压缩课程:http://pastebin.com/0ervqUy6

由于我在应用程序清单中提供了必要的权限(包括Internet权限),因此与Internet权限无关。

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。但我解决了!

这很简单,你必须解压缩epub文件。

不需要使用AsyncTask进行解压缩。 这是我的解压缩代码:

public static String unzip(String path, String zipname) {
    InputStream is;
    ZipInputStream zis;
    String folderName = null;
    try {
        String filename;
        is = new FileInputStream(path + zipname);
        zis = new ZipInputStream(new BufferedInputStream(is));
        ZipEntry ze;
        byte[] buffer = new byte[1024];
        int count;
        boolean firstLoop = true;
        while ((ze = zis.getNextEntry()) != null) {
            // zapis do souboru
            filename = ze.getName();
            if (firstLoop) {
                folderName = filename;
                firstLoop = false;
            }
            // Need to create directories if not exists, or
            // it will generate an Exception...
            if (ze.isDirectory()) {
                File fmd = new File(path + filename);
                fmd.mkdirs();
                continue;
            }

            FileOutputStream fout = new FileOutputStream(path + filename);

            // cteni zipu a zapis
            while ((count = zis.read(buffer)) != -1) {
                fout.write(buffer, 0, count);
            }

            fout.close();
            zis.closeEntry();
        }

        zis.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return folderName;
}

不要忘记在BookInformation上设置SkyProvider。

            SkyProvider skyProvider = new SkyProvider();
            book.isDownloaded = true;
            book.setFileName(fileName);
            book.setBaseDirectory(baseDirectory);
            book.setContentProvider(skyProvider);
            skyProvider.setBook(book.getBook());
            skyProvider.setKeyListener(new KeyDelegate());
            book.makeInformation();