title: Crash when try to open camera android?
body: <p>I need to open camera and take picture and display in imageview. </p>
  
  <p>But problem is I am getting crash as below. I cleaned the build and ran. But still this problem occurs. </p>
  
  <pre><code> Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/com.trial.learn/files/Pictures/JPEG_20180515_104113_6007506636120272936.jpg
                                                                       at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:711)
                                                                       at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)
                                                                       at com.trial.learn.MainActivity.openCamera(MainActivity.java:57)
                                                                       at com.trial.learn.MainActivity.checkCameraPermission(MainActivity.java:37)
                                                                       at com.trial.learn.MainActivity.onCreate(MainActivity.java:31)
                                                                       at android.app.Activity.performCreate(Activity.java:6998)
                                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1230)
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046) 
                                                                       at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688) 
                                                                       at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                       at android.os.Looper.loop(Looper.java:164) 
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6809) 
                                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                                       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
  </code></pre>
  
  <p>Here is code. I am clueless what mistake I am doing. Kindly correct me.</p>
  
  <p>I even added permissions in manifest file too. </p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      private String mCurrentPhotoPath,mCurrentPhotoPathResize;
      private ImageView imageView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          imageView = (ImageView)findViewById(R.id.imageView);
          checkCameraPermission();
      }
      private void checkCameraPermission() {
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M)
              if (!checkPermission(this, Manifest.permission.CAMERA, 123))
                  checkPermission(this, Manifest.permission.CAMERA, 123);
              else openCamera();
          else openCamera();
      }
      private void openCamera() {
          Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  
          if (takePictureIntent.resolveActivity(this.getPackageManager()) != null) {
              File photoFile = null;
              File photoFile2 = null;
              try {
                  photoFile = ImageResizeUtility.createImageFile(this);
                  photoFile2 = ImageResizeUtility.createImageFile2(this);
              } catch (IOException ex) {
                  // Error occurred while creating the File
              }
              mCurrentPhotoPath = photoFile.getAbsolutePath();
              mCurrentPhotoPathResize = photoFile2.getAbsolutePath();
              Log.e("url",mCurrentPhotoPath);
              Log.e("urls",mCurrentPhotoPathResize);
  
              Uri photoURI = FileProvider.getUriForFile(MainActivity.this, "com.trial.learn.authority", photoFile);
              takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
              startActivityForResult(takePictureIntent, 111);
          }
      }
  
      public static boolean checkPermission(Activity context, String permission, int requestCode) {
          if (ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
              ActivityCompat.requestPermissions(context,
                      new String[]{permission},
                      requestCode);
              return false;
          } else {
              return true;
          }
      }
  
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          if (requestCode == 111 &amp;&amp; resultCode == RESULT_OK) {
              ImageResizeUtility.compressImage(this, mCurrentPhotoPath, mCurrentPhotoPathResize, imageView);
              String _imagePath = mCurrentPhotoPathResize;
              Log.e("urlOnActivity",_imagePath);
          }
      }
      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
          super.onRequestPermissionsResult(requestCode, permissions, grantResults);
          switch (requestCode) {
              case 123:
                  if (grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED)
                      openCamera();
                  break;
          }
      }
  }
  </code></pre>
  
  <p>xml/file_paths.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;paths xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;external-path name="my_images" path="Android/data/com.trial.learn/files/Pictures" /&gt;
  &lt;/paths&gt;
  </code></pre>
  
  <p><strong>android manifest.xml:</strong></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.CAMERA" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
  
  &lt;provider
              android:name="android.support.v4.content.FileProvider"
              android:authorities="com.trial.learn.authority"
              android:exported="false"
              android:grantUriPermissions="true"&gt;
              &lt;meta-data
                  android:name="android.support.FILE_PROVIDER_PATHS"
                  android:resource="@xml/file_paths" /&gt;
          &lt;/provider&gt;
  </code></pre>