In my application, I am showing epub HTML files in webview
using EPUBLIB.
My problem is that I want to use bookmark functionality for my epub reader. For that I want to fetch text from webview
which is showing page from my epub's HTML file and then use that text in my bookmark activity to show the user what they have bookmarked.
How can I achieve this?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Getting the plain text content from a webview is rather hard. Basically, the android classes don't offer it, but javascript does, and Android offers a way for javascript to pass the information back to your code.
Before I go into the details, do note that if your html structure is simple, you might be better off just parsing the data manually.
That said, here is what you do:
To clarify, I'll post a working (but very rough) code example below. It displays a webview on the top, and a textview with the text-based contents on the bottom.
Using the following main.xml:
The only thing that comes to my mind in this case is to use javascript. Doing a quick search I found
android.webkit.WebView.addJavascriptInterface
.You want to study the "addJavascriptInterface" which in the end will help you solve the problem
The solution provided above provides the text using innerText property which will return you all the text in the webView. The solution that I propose below will help you extract the text from visible part of the webView on the screen.
Step 1: It requires the help of javaScript, hence first enable the javascript.
or
Step 2: Create a javaInterface inner class.
Step 3: Now you have to add the javascript method. You'll write the method as a string and then load it. The method returns the text based on the parameter provided to it. So, you would need 2 strings. One will load the javascript method and the other will call it.
Method to load the javascript method.
Method to call the above function.
Step 4: Now, you need to load the above 2 javascripts.
Enjoy.
Why don't you fetch the text with EPUBLIB from the book directly?
You got that html with the help of EPUBLIB isn't it? How did you put that in the webvieuw? I see no example.