title: Webview camera giving an error, creating picture of 0 bytes before taking picture
body: <p><strong>Those are variables</strong></p>
  <pre><code>    private static final int FILECHOOSER_RESULTCODE = 1;
      private ValueCallback&lt;Uri&gt; mUploadMessage;
      private Uri mCapturedImageURI = null;
  
      // the same for Android 5.0 methods only
      private ValueCallback&lt;Uri[]&gt; mFilePathCallback;
      private String mCameraPhotoPath;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/o1wC9.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o1wC9.jpg" alt="This is the image error icon" /></a></p>
  <p><strong>This is the file chooser code</strong>
  Usually it should create a image after taking the image, but it is creating a blank image before opening the camera intent, and then it is showing an error icon instead of showing the Image.
  <em>Please help me to fix the problem</em></p>
  <pre><code>public boolean onShowFileChooser(
                      WebView webView, ValueCallback&lt;Uri[]&gt; filePathCallback,
                      WebChromeClient.FileChooserParams fileChooserParams) {
                  if (mFilePathCallback != null) {
                      mFilePathCallback.onReceiveValue(null);
                  }
                  mFilePathCallback = filePathCallback;
  
                  Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                  if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
  
                      // create the file where the photo should go
                      File photoFile = null;
                      try {
                          photoFile = createImageFile();
                          takePictureIntent.putExtra(&quot;PhotoPath&quot;, mCameraPhotoPath);
                      } catch (IOException ex) {
                          // Error occurred while creating the File
                          Log.e(TAG, &quot;Unable to create Image File&quot;, ex);
                      }
  
                      // continue only if the file was successfully created
                      if (photoFile != null) {
                          mCameraPhotoPath = &quot;file:&quot; + photoFile.getAbsolutePath();
                          takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                  Uri.fromFile(photoFile));
                      } else {
                          takePictureIntent = null;
                      }
                  }
  
                  Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
                  contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
                  contentSelectionIntent.setType(&quot;image/*&quot;);
  
                  Intent[] intentArray;
                  if (takePictureIntent != null) {
                      intentArray = new Intent[]{takePictureIntent};
                  } else {
                      intentArray = new Intent[0];
                  }
  
                  Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
                  chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
                  chooserIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.image_chooser));
                  chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
  
                  startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);
  
                  return true;
              }
  
              // creating image files (Lollipop only)
              private File createImageFile() throws IOException {
                  // Create an image file name
                  Log.d(TAG, &quot;createImageFile: creating Image&quot;);
                  String timeStamp = new SimpleDateFormat(&quot;yyyyMMdd_HHmmss&quot;).format(new Date());
                  String imageFileName = &quot;JPEG_&quot; + timeStamp + &quot;_&quot;;
                  File storageDir = Environment.getExternalStoragePublicDirectory(
                          Environment.DIRECTORY_PICTURES);
                  File image = File.createTempFile(
                          imageFileName,  // prefix
                          &quot;.jpg&quot;,         // suffix
                          storageDir      // directory
                  );
  
                  // Save a file: path for use with ACTION_VIEW intents
                  mCameraPhotoPath = &quot;file:&quot; + image.getAbsolutePath();
                  return image;enter code here
              }
  
  </code></pre>
  <p><strong>On Activity Result code given below</strong></p>
  <pre><code>    @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
  
          // code for all versions except of Lollipop
          if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.LOLLIPOP) {
  
              if (requestCode == FILECHOOSER_RESULTCODE) {
                  if (null == this.mUploadMessage) {
                      return;
                  }
  
                  Uri result = null;
  
                  try {
                      if (resultCode != RESULT_OK) {
                          result = null;
                      } else {
                          // retrieve from the private variable if the intent is null
                          result = data == null ? mCapturedImageURI : data.getData();
                      }
                  } catch (Exception e) {
                      Toast.makeText(getApplicationContext(), &quot;activity :&quot; + e, Toast.LENGTH_LONG).show();
                  }
  
                  mUploadMessage.onReceiveValue(result);
                  mUploadMessage = null;
              }
  
          } // end of code for all versions except of Lollipop
  
          // start of code for Lollipop only
  
          if (requestCode != FILECHOOSER_RESULTCODE || mFilePathCallback == null) {
              super.onActivityResult(requestCode, resultCode, data);
              return;
          }
  
          Uri[] results = null;
  
          // check that the response is a good one
          if (resultCode == Activity.RESULT_OK) {
              if (data == null || data.getData() == null) {
                  // if there is not data, then we may have taken a photo
                  if (mCameraPhotoPath != null) {
                      results = new Uri[]{Uri.parse(mCameraPhotoPath)};
                  }
              } else {
                  String dataString = data.getDataString();
                  if (dataString != null) {
                      results = new Uri[]{Uri.parse(dataString)};
                  }
              }
          }
  
          mFilePathCallback.onReceiveValue(results);
          mFilePathCallback = null;
  
      }
  </code></pre>