3

I would like to take a screenshot of a page displayed in a WebView. The page contains flash elements - and here is the problem. When I take a screenshot all the flash parts of the page are blank.

I am using this piece of code to take a screenshot:

WebView webView = (WebView) findViewById(R.id.webview);
Picture picture = webView.capturePicture();
Bitmap screenshot = Bitmap.createBitmap(picture.getWidth(),
        picture.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(screenshot);
picture.draw(c);

File file = new File("/sdcard/screenshot.jpg");
FileOutputStream ostream = null;
try {
    file.createNewFile();
    ostream = new FileOutputStream(file);
    screenshot.compress(CompressFormat.JPEG, 90, ostream);
    Log.d("Test", "Screenshot taken");
} catch (Exception e) {
    Log.e("Test", "Error", e);
} finally {
    try {
        ostream.close();
    } catch (IOException ignore) {
    }
}

I was also trying to acquire Bitmap of the screen contents using the solution given in this SO question:

View webView = findViewById(R.id.webview);
Bitmap bitmap = webView.getDrawingCache();

This also doesn't work - the result is the same (i.e. blank flash elements).

So the question is: How to take a screenshot of WebView contents also with flash elements?

Community
  • 1
  • 1
Piotr
  • 5,543
  • 1
  • 31
  • 37
  • If you need to do it once, right now, how about careful use of a digital camera? – Chris Stratton Jul 27 '11 at 20:21
  • Previous comment assumed you'd already tried the DDMS screenshot capability, if you haven't, try that first. – Chris Stratton Jul 27 '11 at 20:24
  • Unfortunately I have to do this from code. A screenshot has to be taken every time user requests it - there will be an item in menu for that. The screenshot will then be shared via facebook, email etc. – Piotr Jul 27 '11 at 20:31
  • Q1: Do you control the flash content? If so, in principle you should be able to have the Flash draw its layout into a bitmap and pass that image data to JS, though the JS and AS images would need to get merged and encoded at some point. – fenomas Jul 28 '11 at 00:02
  • Q2: Which OSs did you try? If it doesn't work I'd assume it's a limitation browser/plugin handling, and that stuff changed quite a bit from gingerbread to honeycomb (and also from froyo to gingerbread, to a lesser extent). – fenomas Jul 28 '11 at 00:03
  • **A1:** I can't change the flash content (it is provided by someone else). **A2:** The highest version I have tested it in was Android 2.3. This is a good idea to test it in newer versions, however there is a requirement that the app works from Android 2.2. – Piotr Jul 28 '11 at 09:28
  • Did you ever figure this out, I'm stuck on the same thing. – Bi Rico Apr 07 '15 at 03:18
  • It was a long time ago but as far as I remember unfortunately I haven't figured this out. – Piotr Apr 08 '15 at 08:53

0 Answers0