title: android.os.FileUriExposedException: file:///storage/emulated/0/image.jpg exposed beyond app through ClipData.Item.getUri()
body: <p>I am trying to open the phone's camera app using the app I am building. But I am getting the below error.</p>
  <p>I have tried solving using the steps mentioned here : [https://stackoverflow.com/questions/48990967/android-os-fileuriexposedexception-file-storage-emulated-0-pictures-picfolde][1]</p>
  <p>But <strong>android:name=&quot;android.support.v4.content.FileProvider&quot;</strong> is showing in red.</p>
  <p>I tried to add the dependency : <strong>compile 'com.android.support:support-v4:27.0.2'</strong> but it is no longer supported.</p>
  <p>My minSdkversion is 21 and targetSdkversion is 30.</p>
  <p>Below is my code for opening camera:</p>
  <pre><code>private void capturePhoto() {
  
      Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      String imageName = &quot;image.jpg&quot;;
      mImageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), imageName)); //result stored in  mImageUri
      cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
      startActivityForResult(cameraIntent, CAPTURE_IMAGE);
  
  
  }
  </code></pre>
  <p>Error message:</p>
  <pre><code>2022-03-06 18:41:02.551 3039-3039/com.beproject.sharepixel E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.beproject.sharepixel, PID: 3039
      android.os.FileUriExposedException: file:///storage/emulated/0/image.jpg exposed beyond app through ClipData.Item.getUri()
          at android.os.StrictMode.onFileUriExposed(StrictMode.java:1796)
          at android.net.Uri.checkFileUriExposed(Uri.java:2346)
          at android.content.ClipData.prepareToLeaveProcess(ClipData.java:845)
          at android.content.Intent.prepareToLeaveProcess(Intent.java:8947)
          at android.content.Intent.prepareToLeaveProcess(Intent.java:8932)
          at android.app.Instrumentation.execStartActivity(Instrumentation.java:1517)
          at android.app.Activity.startActivityForResult(Activity.java:4285)
          at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597)
          at androidx.core.app.ActivityCompat.startActivityForResult(ActivityCompat.java:237)
          at androidx.activity.ComponentActivity$2.onLaunch(ComponentActivity.java:210)
          at androidx.activity.result.ActivityResultRegistry$3.launch(ActivityResultRegistry.java:226)
          at androidx.activity.result.ActivityResultLauncher.launch(ActivityResultLauncher.java:47)
          at androidx.fragment.app.FragmentManager.launchStartActivityForResult(FragmentManager.java:3000)
          at androidx.fragment.app.Fragment.startActivityForResult(Fragment.java:1424)
          at androidx.fragment.app.Fragment.startActivityForResult(Fragment.java:1398)
          at com.beproject.sharepixel.CameraFragment.capturePhoto(CameraFragment.java:136)
          at com.beproject.sharepixel.CameraFragment.access$000(CameraFragment.java:32)
          at com.beproject.sharepixel.CameraFragment$1$1.onClick(CameraFragment.java:94)
          at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:1137)
          at android.widget.AdapterView.performItemClick(AdapterView.java:310)
          at android.widget.AbsListView.performItemClick(AbsListView.java:1164)
          at android.widget.AbsListView$PerformClick.run(AbsListView.java:3132)
          at android.widget.AbsListView$3.run(AbsListView.java:4047)
          at android.os.Handler.handleCallback(Handler.java:751)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:154)
          at android.app.ActivityThread.main(ActivityThread.java:6121)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
  
  
    [1]: https://stackoverflow.com/questions/48990967/android-os-fileuriexposedexception-file-storage-emulated-0-pictures-picfolde
  </code></pre>