4

I'm trying to open URL in a WebView from a background service then take a screenshot of the hidden WebView.

Funnily enough it is not working! Is this possible? Some code snippets:

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

twiz911
  • 634
  • 1
  • 9
  • 18
  • 1
    This is not possible due security – DroidBender May 16 '13 at 09:58
  • please take a look to that post: http://stackoverflow.com/questions/9745988/how-can-i-programmatically-take-a-screenshot-of-a-webview-capturing-the-full-pa – s_bei May 16 '13 at 09:58
  • Stefan - thanks I have code to save the webview, the problem is doing it hidden in a background service. – twiz911 May 16 '13 at 15:51
  • 1
    @MartijnVanMierloo - which bit in particular is not possible due to security? Is there an alternative? Thanks – twiz911 May 16 '13 at 15:51

1 Answers1

1

See my question Android: take a 'screenshot' of a web page from a background service?

You have to get your bitmap from the webview's drawing cache eg.

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

You also have to set the "size" of the WebView, so that it is not 0 x 0 size.

Community
  • 1
  • 1
JonasCz
  • 11,660
  • 6
  • 43
  • 64