这是我尝试执行任务的任务,如果有人可以提供帮助,我将非常感激。因此,在此代码中,它将仅显示封面页。我看了http://www.siegmann.nl/static/epublib/apidocs/您可以使用getSpine()
来获取所有内容,但它只在我的案例中显示了一个封面页。
webView = (WebView)findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
AssetManager am = getAssets();
try {
InputStream epubInputStream = am.open(bookName);
book = (new EpubReader()).readEpub(epubInputStream);
} catch (IOException e) {
Log.e("epublib", e.getMessage());
}
Spine spine = book.getSpine();
for (SpineReference bookSection : spine.getSpineReferences()) {
Resource res = bookSection.getResource();
try {
InputStream is = res.getInputStream();
StringBuffer string = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
try {
while ((line = reader.readLine()) != null) {
linez = string.append(line + "\n").toString();
}
} catch (IOException e) {e.printStackTrace();}
//do something with stream
} catch (IOException e) {
e.printStackTrace();
}
}
webView.loadData(linez, "text/html", "utf-8");
答案 0 :(得分:3)
所以我在http://www.siegmann.nl/static/epublib/apidocs/上使用脊柱的想法是它仍然按部分工作。所以我试图通过识别计数来弄清楚有多少部分。然后将这些数字放在Resource res = spine.getResource(i);
中。如果你愿意Resource res = spine.getResource(2);
它会显示2的主干,这应该是第2章,除非有人弄乱了epub的格式。
Spine spine = book.getSpine();
List<SpineReference> spineList = spine.getSpineReferences() ;
int count = spineList.size();
tv.setText(Integer.toString(count));
StringBuilder string = new StringBuilder();
for (int i = 0; count > i; i++) {
Resource res = spine.getResource(i);
try {
InputStream is = res.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
try {
while ((line = reader.readLine()) != null) {
linez = string.append(line + "\n").toString();
}
} catch (IOException e) {e.printStackTrace();}
//do something with stream
} catch (IOException e) {
e.printStackTrace();
}
}
webView.loadData(linez, "text/html", "utf-8");