4

我解析 epub 文件,但我不明白我可以在 TextView 中设置 epub 吗?或者如何在 TextView 中获取文本内容 EPUB?

    try {
                    InputStream is = getAssets().open("books/testbook.epub");  
                    Book book = new EpubReader().readEpub(is);  
                    Metadata metadata = book.getMetadata();   
                    String bookInfo = ":"+metadata.getAuthors()+  
                            "\n :"+metadata.getPublishers()+  
                            "\n :" +metadata.getDates()+  
                            "\n :"+metadata.getTitles()+  
                            "\n :"+metadata.getDescriptions()+  
                            "\n :"+metadata.getLanguage()+  
                            "\n\n :";  
                    Log.e("epublib", bookInfo);
                    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();
                for(int i=0;i<depth;i++)
                {
                    tocstring.append("\t");
                }
                HashMap<String, String> map = new HashMap<String, String>();
                String k=   tocstring.append(tocReference.getTitle()).toString();
                ArrayList<HashMap<String, String>> list1 = new ArrayList<HashMap<String, String>>();
                list1.add(map);
                 String t=k;
                 Log.i("epublib", tocstring.toString());
                 logTableOfContents(tocReference.getChildren(), depth + 1);

            }           
        }
4

0 回答 0