使用PAUL SIEGMANN库的epub阅读器

时间:2020-08-26 10:40:19

标签: android kotlin epub

我从http://www.siegmann.nl/epublib/download 我想将此代码显示到我的webview中 我是初学者

class Kotlin : AppCompatActivity() {
lateinit var webView: WebView

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_kotlin)
    webView=findViewById(R.id.kotlinwebview)
    val assetManager = assets
    try {
        // find InputStream for book
        val epubInputStream = assetManager
            .open("books/testbook.epub")

        // Load Book from inputStream
        val book = EpubReader().readEpub(epubInputStream)

        // Log the book's authors
        Log.i("epublib", "author(s): " + book.metadata.authors)

        // Log the book's title
        Log.i("epublib", "title: " + book.title)

        // Log the book's coverimage property
        val coverImage = BitmapFactory.decodeStream(
            book.coverImage.inputStream
        )
        Log.i(
            "epublib", "Coverimage is " + coverImage.width + " by "
                    + coverImage.height + " pixels"
        )

        // Log the tale of contents
        logTableOfContents(book.tableOfContents.tocReferences, 0)
    } catch (e: IOException) {
        Log.e("epublib", e.message!!)
    }
}

/**
 * Recursively Log the Table of Contents
 *
 * @param tocReferences
 * @param depth
 */
private fun logTableOfContents(tocReferences: List<TOCReference>?, depth: Int) {
    if (tocReferences == null) {
        return
    }
    for (tocReference in tocReferences) {
        val tocString = StringBuilder()
        for (i in 0 until depth) {
            tocString.append("\t")
        }
        tocString.append(tocReference.title)
        Log.i("epublib", tocString.toString())
        logTableOfContents(tocReference.children, depth + 1)
    }
}

}

我的webview是我想从资产中读取一个epub文件并在webview中显示

lateinit var webView: WebView

我已插入网站中提供的两个库 进入库 感谢您提前帮助我

0 个答案:

没有答案
相关问题