因此,我正在尝试使用 Epublib 在单个 WebView 中加载封面和章节内容(按其各自的顺序)。到目前为止,我所做的......我从云端检索了我的 epub 文件,并使用以下代码使用 epublib 库解压缩:
try {
EpubReader epubReader = new EpubReader();
Book book = epubReader.readEpub(inputStream);
inputStream.close();
return book;
} catch (IOException e) {
Log.e("Exception: ", e.toString());
}
解压后,我可以访问cover.xhtml 和chapter-1.xhtml(以及其他一些文件),我将它们写入临时目录中的文件:
private File writeFile(File tempFile, String fileData) throws IOException {
BufferedWriter bWriter = new BufferedWriter(new FileWriter(tempFile));
bWriter.write(fileData);
tempFile.deleteOnExit();
return tempFile;
}
现在,我尝试将cover.xhtml 页面导入chapter-1.xhtml 页面中,假设它将加载到单个WebView 中。
//get file to load on webview
File file = new File(contentFilePath);
// Check if content file exists or not
if (!file.exists()) { System.out.println("Does not exist");}
else {
System.out.println("Exists");
String contentData = readFile(file);
Document doc = Jsoup.parse(contentData);
doc.head().prependElement("link").attr("rel", "import").attr("href","cover.xhtml");
webView.loadDataWithBaseURL("file://"+tempDir.getAbsolutePath()+"/", contentData, "application/xhtml+xml", "UTF-8", null);
}
但是,尽管显示了内容页面,但这似乎并没有加载封面。任何帮助深表感谢。