title: Capture Image From Camera using intent creates empty Image file
body: <p>I followed this tutorial : <a href="https://developer.android.com/training/camera/photobasics" rel="nofollow noreferrer">https://developer.android.com/training/camera/photobasics</a> .
  I had some errors, but I resolved them and the app was working fine.
  Once you took a picture, the picture would be saved in under this path :
  <code>Android/data/&lt;YourAppPackageName&gt;/files/Pictures</code>.
  <strong>However, after last OS update I'm getting an empty image file with size 0 B!</strong></p>
  <p>How can I solve this issue?</p>
  <p>here is my github project : <a href="https://github.com/AlineJo/CameraGalleryImage.git" rel="nofollow noreferrer">https://github.com/AlineJo/CameraGalleryImage.git</a></p>
  <p>here is my code :</p>
  <p><strong>Manifest.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;com.example.cameragalleryimage&quot;&gt;
      &lt;!--Permission to write to storage--&gt;
      &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
      &lt;!--Inform google play that your app can take pictures--&gt;
      &lt;uses-feature
          android:name=&quot;android.hardware.camera&quot;
          android:required=&quot;true&quot; /&gt;
  
  
      &lt;application
          android:allowBackup=&quot;true&quot;
          android:icon=&quot;@mipmap/ic_launcher&quot;
          android:label=&quot;@string/app_name&quot;
          android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
          android:supportsRtl=&quot;true&quot;
          android:theme=&quot;@style/AppTheme&quot;&gt;
  
          &lt;!-- File provider is a generic way to store image file across different Android SDK, And it enable us to get uri--&gt;
          &lt;provider
              android:name=&quot;androidx.core.content.FileProvider&quot;
              android:authorities=&quot;com.example.cameragalleryimage.fileprovider&quot;
              android:exported=&quot;false&quot;
              android:grantUriPermissions=&quot;true&quot;&gt;
              &lt;meta-data
                  android:name=&quot;android.support.FILE_PROVIDER_PATHS&quot;
                  android:resource=&quot;@xml/img_file_path&quot;&gt;&lt;/meta-data&gt;
          &lt;/provider&gt;
  
  
          &lt;activity android:name=&quot;.activities.MainActivity&quot;&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  <p><strong>UploadImageFragment</strong></p>
  <pre><code>package com.example.cameragalleryimage.fragments;
  
  
  import android.Manifest;
  import android.content.Context;
  import android.content.Intent;
  import android.content.pm.PackageManager;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.net.Uri;
  import android.os.Bundle;
  import android.os.Environment;
  import android.provider.MediaStore;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.ImageView;
  import android.widget.ProgressBar;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import androidx.annotation.NonNull;
  import androidx.annotation.Nullable;
  import androidx.core.app.ActivityCompat;
  import androidx.core.content.FileProvider;
  import androidx.fragment.app.Fragment;
  
  import com.example.cameragalleryimage.R;
  
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStream;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  
  import static android.app.Activity.RESULT_OK;
  
  /**
   * A simple {@link Fragment} subclass.
   */
  public class UploadImageFragment extends Fragment implements ChooseDialogFragment.ChooseDialogInterface {
  
  
      private static final int PICK_IMAGE = 100;
      private static final int CAPTURE_IMAGE = 200;
      private static final int STORAGE_PERMISSION_REQUEST = 300;
      private Context mContext;
      private Uri mImageUri;
      private ImageView ivImg;
  
      private TextView tvProgress;
      private ProgressBar progressBar;
      private String mImagePath;
  
      public UploadImageFragment() {
          // Required empty public constructor
      }
  
      @Override
      public void onAttach(@NonNull Context context) {
          super.onAttach(context);
          mContext = context;
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View parentView = inflater.inflate(R.layout.fragment_upload_image, container, false);
  
          ivImg = parentView.findViewById(R.id.iv_img);
          tvProgress = parentView.findViewById(R.id.tv_progress);
          progressBar = parentView.findViewById(R.id.progressBar);
  
  
          Button btnChoose = parentView.findViewById(R.id.btn_choose);
          Button btnUpload = parentView.findViewById(R.id.btn_upload);
  
          btnChoose.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  ChooseDialogFragment dialog = new ChooseDialogFragment();
                  dialog.setChooseDialogListener(UploadImageFragment.this);
                  dialog.show(getChildFragmentManager(), ChooseDialogFragment.class.getSimpleName());
              }
          });
  
  
          btnUpload.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (mImageUri == null) {
                      Toast.makeText(mContext, &quot;Please take an image&quot;, Toast.LENGTH_SHORT).show();
                  } else {
                      Toast.makeText(mContext, &quot;Image URI Found : &quot; + mImageUri.toString(), Toast.LENGTH_LONG).show();
                  }
              }
          });
          return parentView;
      }
  
  
      @Override
      public void onGalleryButtonClick() {
          Intent i = new Intent();
          i.setType(&quot;image/*&quot;); // specify the type of data you expect
          i.setAction(Intent.ACTION_GET_CONTENT); // we need to get content from another act.
          startActivityForResult(Intent.createChooser(i, &quot;choose App&quot;), PICK_IMAGE);
      }
  
      @Override
      public void onCameraButtonClick() {
          if (isPermissionGranted()) {
              openCamera();
          } else {
              showRunTimePermission();
          }
      }
  
      private void openCamera() {
          Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          // Ensure that there's a camera activity to handle the intent
          if (takePictureIntent.resolveActivity(mContext.getPackageManager()) != null) {
              // Create the File where the photo should go
              File photoFile = null;
              try {
                  photoFile = createImageFile();
              } catch (IOException ex) {
                  // Error occurred while creating the File
                  Log.d(&quot;capture_error&quot;, ex.toString());
              }
  
              // Continue only if the File was successfully created
              if (photoFile != null) {
                  mImageUri = FileProvider.getUriForFile(mContext,
                          &quot;com.example.cameragalleryimage.fileprovider&quot;,
                          photoFile);
  
                  startActivityForResult(takePictureIntent, CAPTURE_IMAGE);
              }
          }
      }
  
  
      @Override
      public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          if (resultCode == RESULT_OK &amp;&amp; data != null) {
              if (requestCode == CAPTURE_IMAGE) {//img from camera
                  Bundle extras = data.getExtras();
                  Bitmap imageBitmap = (Bitmap) extras.get(&quot;data&quot;);
                  ivImg.setImageBitmap(imageBitmap);
              } else if (requestCode == PICK_IMAGE) {// img from gallery
                  try {
                      Uri imgUri = data.getData();
                      InputStream imageStream = mContext.getContentResolver().openInputStream(imgUri);//2
                      Bitmap selectedImageBitmap = BitmapFactory.decodeStream(imageStream);//3}
                      mImageUri = imgUri;
                      ivImg.setImageBitmap(selectedImageBitmap);
  
                  } catch (FileNotFoundException e) {
                      e.printStackTrace();
                  }
              }
  
          } else {
              Toast.makeText(mContext, &quot;Unexpected Error Happened while selecting  picture!&quot;, Toast.LENGTH_SHORT).show();
  
          }
  
  
      }
  
  
      private File createImageFile() throws IOException {
          // Create an image file name
          String timeStamp = new SimpleDateFormat(&quot;yyyyMMdd_HHmmss&quot;).format(new Date());
          String imageFileName = &quot;IMG_&quot; + timeStamp + &quot;_&quot;;
          File storageDir = mContext.getExternalFilesDir(Environment.DIRECTORY_PICTURES);// mContext.getExternalCacheDir();
          File image = File.createTempFile(
                  imageFileName,  /* prefix */
                  &quot;.jpg&quot;,         /* suffix */
                  storageDir      /* directory */
          );
  
          // Save a file: path for use with ACTION_VIEW intents
          mImagePath = image.getAbsolutePath();
          return image;
      }
  
  
      private boolean isPermissionGranted() {
          return ActivityCompat.checkSelfPermission(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
      }
  
      public void showRunTimePermission() {
          // Permission is not Granted !
          // we should Request the Permission!
          // put all permissions you need in this Screen into string array
          String[] permissionsArray = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
  
          //here we requet the permission
          requestPermissions(permissionsArray, STORAGE_PERMISSION_REQUEST);
      }
  
      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
          super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  
          if (grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
              // user grants the Permission!
              // you can call the function to write/read to storage here!
              openCamera();
  
          } else {
              // user didn't grant the Permission we need
              Toast.makeText(mContext, &quot;Please Grant the Permission To use this Feature!&quot;, Toast.LENGTH_LONG).show();
          }
      }
  
  
  }
  </code></pre>
  <p><strong>img_file_path.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;paths&gt;
      &lt;external-files-path
          name=&quot;my_images&quot;
          path=&quot;/&quot; /&gt;
      &lt;!--    Android/data/com.example.cameragalleryimage/files/Pictures--&gt;
  &lt;/paths&gt;
  </code></pre>