Issue
I have an android application in which I need to get the HTML code of the page that will be loaded in the webview. This code I need to get it even before the page loads in the webview and act accordingly.
I am trying to capture the URL that would be loaded in the method
"public void onPageStarted(WebView view, String url, Bitmap favicon)"
But what is the way to get the HTML code of the page that would be loaded in the webview?
Solution
I don't know for how to get webview content, but I am using this for code of webpage
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("website url");
HttpResponse response = httpClient.execute(httpGet, localContext);
String result = "";
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent()
)
);
String line = null;
while ((line = reader.readLine()) != null){
result += line + "\n";
}
The second method is,
URL url;
try {
// url = new URL(data.getScheme(), data.getHost(), data.getPath());
url = new URL("website url");
BufferedReader rd = new BufferedReader(new InputStreamReader(
url.openStream()));
String line = "";
while ((line = rd.readLine()) != null) {
text.append(line);
}
} catch (Exception e) {
e.printStackTrace();
}
Answered By - user370305
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.