Kowlown
Kowlown

Reputation: 1166

How to read a epub file with skyepub?

I wanted to use the skyepub SDK to read my epub books. But when i want to read an epub i keep getting a blank screen with :

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.

I unzip each book i want to read in the Application Android directory so i guess it's not related to unziping.

Here is the code : http://pastebin.com/BuC9DJsf

Unzip class : http://pastebin.com/0ervqUy6

It's not related to the internet permission since i put the necessary permissions (including internet permission) in my application manifest.

Upvotes: 2

Views: 890

Answers (1)

uiltonsantos
uiltonsantos

Reputation: 409

I had the same problem. But I solved it!

That's simple, you must to unzip the epub file.

It's not need to use AsyncTask for unzip. Here is my unzip code:

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

Do not forget to set SkyProvider on BookInformation.

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

Upvotes: 2

Related Questions