Android Open WebView in the background and screen capture

I am trying to open a URL in a WebView from a background service, and then take a screenshot of a hidden WebView.

Oddly enough, this does not work! Is it possible? Some snippets of code:

webView.setVisibility(View.INVISIBLE); ... final Picture picture = webView.capturePicture(); final Bitmap b = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888); final Canvas c = new Canvas(b); picture.draw(c); .... 

thanks

+4
source share
1 answer

See my Android question : take a โ€œscreenshotโ€ of a web page from a background service?

You should get a bitmap from the web browser drawing cache, for example.

 mWebView.setDrawingCacheEnabled(true); Bitmap b = mWebView.getDrawingCache(); 

You also need to set the โ€œsizeโ€ of the WebView so that it is not 0 x 0.

+1
source

Source: https://habr.com/ru/post/1481137/


All Articles