我想在我的应用程序中使用epub书。 我发现这个链接http://www.siegmann.nl/epublib/android打开我的epub书。android epublib访问css,图像,url内部文件
我知道如何显示来自EPUB书的文本,
,但我有一个图片,CSS文件和链接的一个问题。他们的网址是资产文件夹,例如:
文件:///android_asset/index_split_000.html#back_note_1 文件:///android_asset/images/image-1.jpeg
而在资产文件夹没有像这样的HTML页面,没有图像文件夹,只有epub压缩文件。
如何使用所有内部文件?
我的代码:
WebView webView=(WebView) findViewById(webView);
List<Chapter> chapters=new ArrayList<Chapter>();
AssetManager assetManager = getAssets();
try{
//find input Stream for book
InputStream epubInputStream = assetManager.open("xxxxx.epub");
//Load book from input stream
book = (new EpubReader()).readEpub(epubInputStream);
//Log the book's cover image property
Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage().getInputStream());
//Log.i("epublib", "CoverImage is" + coverImage.getWidth()+" by "+coverImage.getHeight()+" pixels");
//Log the tables of contents
logTableOfContents(book.getTableOfContents().getTocReferences(),0);
}
catch(IOException e){
Log.e("epublib", e.getMessage());
}
private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
if (tocReferences == null) {
return;
}
for (TOCReference tocReference : tocReferences) {
StringBuilder tocString = new StringBuilder();
try {
Chapter chapter=new Chapter();
String s=new String(tocReference.getResource().getData());
chapter.setTitle(tocReference.getTitle());
chapter.setContent(s);
chapters.add(chapter);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
logTableOfContents(tocReference.getChildren(), depth + 1);
}
}
章是我自己的类:
public class Chapter {
String title;
String content;
public Chapter(String titlt,String content) {
this.title=titlt;
this.content=content;
}
public Chapter() {
}
public String getTitle() {
return title;
}
public String getContent() {
return content;
}
public void setTitle(String title) {
this.title = title;
}
public void setContent(String content) {
this.content = content;
}
}
将数据加载到网页视图:
webView.loadDataWithBaseURL("file:///android_asset/",chapters.get(index).getContent(), "text/html", "utf-8", null);
不能多谢你。先生,你是救命的人。 –