title: Android - how to take snapshot of web-view on click
body: <p>i want to take webview screenshot to sdcard.</p>
  
  <p>i am using following to get webpage in webview</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      mService = new BluetoothService(this, mHandler);
      setContentView(R.layout.main);
      web = (WebView) findViewById(R.id.webView1);
      setUpWebView();
      web.loadUrl("http://www.domain.com");
  }
  </code></pre>
  
  <p>i want to put snapshot code here in following on click function.</p>
  
  <pre><code>class ClickEvent implements View.OnClickListener {
      public void onClick(View v) {
           ???????????????????????
     }}
  </code></pre>
  
  <p>please help me as i am tring from last two days different code tried but no luck</p>
  
  <p>i tried following code suggested, but this is closing down app.</p>
  
  <pre><code>w = new WebView(this);
     w.setWebViewClient(new WebViewClient()
      {
          public void onPageFinished(WebView view, String url)
          {
                  Picture picture = view.capturePicture();
                  Bitmap  b = Bitmap.createBitmap( picture.getWidth(),
                  picture.getHeight(), Bitmap.Config.ARGB_8888);
                  Canvas c = new Canvas( b );
  
                  picture.draw( c );
                  FileOutputStream fos = null;
                  try {
  
                      fos = new FileOutputStream( "mnt/sdcard/yahoo.jpg" );
                          if ( fos != null )
                          {
                              b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
  
                              fos.close();
                          }
                      }
                 catch( Exception e )
                 {
  
                 }
        }
    });
  
  setContentView(w);
  w.loadUrl("http://search.yahoo.com/search?p=android");
   }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.activity_main, menu);
  return true;
  }}
  </code></pre>
  
  <p>thanks for your help.</p>
  
  <p>regards,</p>