I just want to know when the html page loads. OnPageFinished is called before the entire page loads. I got a blank view when I installed Image View using a bitmap created from WebView
mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setAlwaysDrawnWithCacheEnabled(true); mWebView.setWebViewClient(new WebViewClient(){ @Override public void onPageStarted(WebView view, String url, Bitmap favicon){ super.onPageStarted(view, url, favicon); } @Override public void onPageFinished(WebView view,String url){ Bitmap b = Bitmap.createBitmap( 480, 240, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); view.layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()); view.draw(c); mImageView.setImageBitmap(b);
EDIT:
I tried to implement JavaScriptInterface now only with the creation of a Toast post, but it still doesn't work. I pasted the html code and Java:
EDIT:
Finally, I started to work. I used JavaScriptInterface with the correct one. When loadUrl starts, the html file is loaded. When the entire page is accessible on the screen, the onload function of the html file calls the captureImage function from the JavaScriptInterface class. Now Iโm sure that the page is fully loaded and I can view it. Thanks for the help.
CODE:
JAVA:
mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setDrawingCacheEnabled(true); mWebView.addJavascriptInterface(new JavaScriptInterface(this), "Android"); mWebView.setWebViewClient(new WebViewClient(){}); mButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mWebView.loadUrl("file:///android_asset/html_sample.html");
HTML:
<html> <head> <title>My first styled page</title> <link rel="stylesheet" href="sample_css.css"> </head> <body onload="function(){ Android.captureImage() }"> ... </body> </html>
source share