Reputation: 79
i tried different codes but fail very time. i got webview containing text i would like to take all text into string.
here i can getting webview
browser = (WebView) findViewById(R.id.webView);
browser.getSettings().setLoadsImagesAutomatically(true);
browser.getSettings().setJavaScriptEnabled(true);
browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
browser.setWebViewClient(new MyBrowser());
browser.loadUrl("domain.com/textcontacinfile.html");
please help me in this
thanks
Upvotes: 0
Views: 532
Reputation: 4185
To get text content from HTML, use XmlPullParser.
Here are references:
private String readText(String htmlStr) throws IOException, XmlPullParserException {
String toReturn = "";
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader ("htmlStr"));
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.TEXT) {
toReturn = "Text "+ xpp.getText());
}
eventType = xpp.next();
}
return toReturn;
}
Upvotes: 1