这是我试图执行任务,如果有人可以帮助它将是非常感谢.因此,在此代码中,它将仅显示封面页.我阅读了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");
Run Code Online (Sandbox Code Playgroud)
所以我发现在http://www.siegmann.nl/static/epublib/apidocs/上使用spine它仍然可以按部分工作。所以我试图通过识别计数来找出有多少个部分。然后将这些数字放入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");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2896 次 |
| 最近记录: |