title: Take a screenshot of a video in a webview android
body: <p>I am working on a project where I save a screenshot in a WebView. API Level is 21. On a normal homepage it works absolutely fine, but when I visit youtube and watch a video, the video player returns as a black rectangle.
  What I want to do is take a screenshot whenever the user touches the screen.</p>
  
  <p>When I take a screenshot with Power &amp; Volume Button it works perfectly. Is there an Intent which takes this kind of a screenshot? Ideally the screenshot would only contain the webview, but if it's the entire screen I can work with that too.</p>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>Cheers,</p>
  
  <p>Toby</p>
  
  <p>Edit: some of my code</p>
  
  <pre><code>View rootView;
  ValueCallback&lt;String&gt; callback = new ValueCallback&lt;String&gt;() {
      @Override
      public void onReceiveValue(String value) {
          category1.setText(value);
      }
  };
  String root = android.os.Environment.getExternalStoragePublicDirectory
          (Environment.DIRECTORY_DCIM).toString(), filename, time, puretime, movementType = ""; //movementType is set according to MotionEvent.getAction()
  File myDir = new File(root + "/saved_files/")
  
  protected void onCreate(Bundle savedInstanceState) {
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      super.onCreate(savedInstanceState);
  
      rootView = findViewById(android.R.id.content).getRootView();
      rootView.setDrawingCacheEnabled(true);
  }
  
  public class MyView extends View {
      public MyView(Context context) {
          super(context);
      }
  
      @Override
      public boolean onTouchEvent(MotionEvent event) {
          calendar = Calendar.getInstance();
          time = String.format("%02d:%02d:%02d.%03d", calendar.get(Calendar.HOUR_OF_DAY),
                  calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND),
                  calendar.get(Calendar.MILLISECOND));
          puretime = String.format("%02d%02d%02d%03d", calendar.get(Calendar.HOUR_OF_DAY),
                  calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND),
                  calendar.get(Calendar.MILLISECOND));
          if (movementType.equals("down")) {
              try {
                  filename = puretime + ".xml";
                  webView.saveWebArchive(myDir+filename, false, callback);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
          invalidate();
          return true;
      }
  </code></pre>
  
  <p>edit2:</p>
  
  <p>apparently the problem for the black rectangles is that elements as the video are processed by the gpu and for a "normal" snapshot to work the program would need to calculate every frame which is too much work.</p>