Screenshot of a webpage with Flash elements

2019-04-12 05:48发布

问题:

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?