0

Are there any APIs available for taking the screenshot of a WebView which contains complete WebView (Including the parts which are not part of the current view, but can be accessed by scrolling the WebView) ?

I found in previous questions asked in this site is using deprecated methods and those methods are not rendering the screenshots properly.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
AtHul Antony
  • 77
  • 1
  • 11
  • 1
    Possible duplicate of [How can I programmatically take a screenshot of a webview, capturing the full page?](http://stackoverflow.com/questions/9745988/how-can-i-programmatically-take-a-screenshot-of-a-webview-capturing-the-full-pa) – Lyth Feb 08 '17 at 15:32
  • Not a duplicate. The method in that answer is deprecated and not rendering properly. – AtHul Antony Feb 09 '17 at 05:31

1 Answers1

0

For those who are checking for the answer, From other questions I found the answer .

     wvWb = (WebView) findViewById(R.id.wvMy);
    wvWb.getSettings().setJavaScriptEnabled(true);
    wvWb.loadUrl("http://www.entri.me");
    wvWb.setWebViewClient(new WebViewClient() {
     @Override
        public void onPageFinished(WebView view, String url) {
          String root = Environment.getExternalStorageDirectory().toString();
            File myDir = new File(root + "/11111");
            myDir.mkdirs();
            Random generator = new Random();
            int n = 10000;
            n = generator.nextInt(n);
            String fname = "Image-" + n + ".jpg";
            File file = new File(myDir, fname);
            wvWb.setDrawingCacheEnabled(true);
         wvWb.setDrawingCacheEnabled(false);
         wvWb.measure(android.view.View.MeasureSpec.makeMeasureSpec(
                    android.view.View.MeasureSpec.UNSPECIFIED, android.view.View.MeasureSpec.UNSPECIFIED),
                    android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View.MeasureSpec.UNSPECIFIED));
            wvWb.layout(0, 0, wvWb.getMeasuredWidth(),
                    wvWb.getMeasuredHeight());
            wvWb.setDrawingCacheEnabled(true);
            wvWb.buildDrawingCache();
            Bitmap bm = Bitmap.createBitmap(wvWb.getMeasuredWidth(),
                    wvWb.getMeasuredHeight(), Bitmap.Config.ARGB_8888);

            Canvas bigcanvas = new Canvas(bm);
            Paint paint = new Paint();
            int iHeight = bm.getHeight();
            bigcanvas.drawBitmap(bm, 0, iHeight, paint);
            wvWb.draw(bigcanvas);


            if (bm != null) {

                try {
                    OutputStream fOut = null;
                    fOut = new FileOutputStream(file);

                    bm.compress(Bitmap.CompressFormat.PNG, 50, fOut);

                    fOut.flush();
                    fOut.close();

                } catch (Exception e) {
                    e.printStackTrace();
                }


            }
        }
    });
AtHul Antony
  • 77
  • 1
  • 11