title: java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Pictures/
body: <p>Looking for some help on an error I am getting while trying to store Pictures taken with the camera for an App I am trying to develop. The error is </p>
  
  <p>java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Pictures/JPEG20161108_153704_</p>
  
  <p>The logcat points to this method in my code at the line where FileProvider.getUriForFile is being called..</p>
  
  <pre><code>private void dispatchTakePhoto() {
          Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          startActivity(takePictureIntent); // this worked originally
          if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
              File photoFile = null;
              try {
                  photoFile = createImageFile();
              } catch (IOException e) {
                  e.printStackTrace();
                  Log.e(TAG, ""+e);
              }
              if (photoFile != null) {
                  Uri photoURI = FileProvider.getUriForFile(TallyActivity2.this,
                          "com.example.bigdaddy.pipelinepipetally.fileprovider", photoFile);
                  takePictureIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                  takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                  startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
              }
          }
      }
  </code></pre>
  
  <p>This method is used to create the image file</p>
  
  <pre><code> private File createImageFile() throws IOException {
          /* Create an image file name */
          String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
          String imageFileName = "JPEG" + timeStamp + "_";
          File storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsoluteFile(), imageFileName);
          File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
  
          /* Tried this also, not working. Leaving for debugging.
          File image = File.createTempFile(
                  imageFileName,
                  ".jpg",
                  storageDir
          );*/
  
          File image = new File(path, imageFileName);
          try {
              /* Making sure the Pictures directory exist.*/
              path.mkdir();
              storageDir.createNewFile();
          }catch (Exception e) {
              e.printStackTrace();
          }
  
          /* Save a file: path for use with ACTION_VIEW intents */
          mCurrentPhotoPath = "file:" + image.getAbsolutePath();
          return image;
      }
  </code></pre>
  
  <p>Here is the <code>onActivityResult()</code> method, where I am wanting to save the image captured to a class with the saveImage() method and also setting the thumbnail to an <code>ImageView</code>. The saveImage() method returns a byte so I can pass the byte in a Bundle through an Intent to another full screen activity, where it will be displayed, should the user click on the thumbnail <code>ImageView</code>.</p>
  
  <pre><code>@Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          /* If it's equal to my REQUEST_IMAGE_CAPTURE var, we are all good. */
          if (requestCode == REQUEST_IMAGE_CAPTURE &amp;&amp; resultCode == RESULT_OK) {
              Bundle extras = data.getExtras();
              Bitmap imageBitmap = (Bitmap) extras.get("data");
              /*Saving to the Pipe class with the saveImage() method below.*/
              sDummyImagePicByte = saveImage(imageBitmap);
              /* Going ahead an setting the thumbnail here for the picture taken*/
              mPipePicImage.setImageBitmap(imageBitmap);
              Log.i(TAG,Arrays.toString(sDummyImagePicByte)+" after assignment from saveImage()");
          }
      }
  </code></pre>
  
  <p>Here is the <code>Manifest.xml</code> file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            package="com.example.bigdaddy.pipelinepipetally"&gt;
  
      &lt;uses-permission android:name="android.permission.READ_CONTACTS"/&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
          android:maxSdkVersion="18"/&gt;
      &lt;uses-permission android:name="android.permission.CAMERA"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/&gt;
  
      &lt;application
          android:allowBackup="true"
          android:debuggable="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"
          tools:ignore="HardcodedDebugMode"&gt;
          &lt;activity
              android:name=".MainActivity"
              android:windowSoftInputMode="adjustResize"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN"/&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER"/&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=".TallyActivity2"
              android:windowSoftInputMode="adjustResize"&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=".JobAndDbActivity"
              android:windowSoftInputMode="adjustResize"&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=".ExistingTallyActivity"
              android:windowSoftInputMode="adjustResize"&gt;
          &lt;/activity&gt;
          &lt;activity android:name=".ImageToFullscreen"
              android:windowSoftInputMode="adjustResize"&gt;
          &lt;/activity&gt;
  
          &lt;provider
              android:name="android.support.v4.content.FileProvider"
              android:authorities="com.example.bigdaddy.pipelinepipetally.fileprovider"
              android:exported="false"
              android:grantUriPermissions="true"&gt;
              &lt;meta-data
                  android:name="android.support.FILE_PROVIDER_PATHS"
                  android:resource="@xml/file_paths"&gt;
              &lt;/meta-data&gt;
          &lt;/provider&gt;
  
      &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Here is the <code>file_paths.xml</code> file that I created and put in the app/res/xml/ folder (which I created also). Not sure if this is the correct location (for the folder).</p>
  
  <pre><code>&lt;paths &gt;
      &lt;files-path name="my_images" path="files/"/&gt;
      ...
  &lt;/paths&gt;
  </code></pre>
  
  <p>Also this is the <code>onRequestPermissionsResult()</code></p>
  
  <pre><code> @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
                                             @NonNull int[] grantResults) {
          super.onRequestPermissionsResult(requestCode, permissions, grantResults);
          switch (requestCode) {
              case MY_PERMISSIONS_REQUEST_CAMERA:
                  /* if request is canceled, the result arrays are empty */
                  if(grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED){
                      /* Permissions granted so the mPermissionIsGranted boolean is set to true*/
                      mPermissionIsGranted = true;
                  } else {
                      /*
                      Permissions denied so the mPermissionIsGranted boolean stays false here and
                      providing a Toast message to the user, letting them know that camera permissions
                      are required for this feature.
                      */
                      Toast.makeText(getApplicationContext(),"Camera permissions required\nfor this" +
                                      "feature.",
                              Toast.LENGTH_LONG).show();
                      /* Continuing to hold the false setting to this boolean since not granted.*/
                      mPermissionIsGranted = false;
                  }
                  break;
              /* For accessing and writing to the SD card*/
              case MY_PERMISSIONS_REQUEST_SD_CARD:
                  /* if request is canceled, the result arrays are empty */
                  if(grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED){
                      /* Permissions granted so the mPermissionIsGranted boolean is set to true*/
                      mPermissionIsGranted = true;
                  } else  {
                      /*
                      Permissions denied so the mPermissionIsGranted boolean stays false here and
                      providing a Toast message to the user, letting them know that camera permissions
                      are required for this feature.
                      */
                      Toast.makeText(getApplicationContext(),"SD Card permissions required\nfor this"+
                                      "feature.",
                              Toast.LENGTH_LONG).show();
                      /* Continuing to hold the false setting to this boolean since not granted.*/
                      mPermissionIsGranted = false;
                  }
                  break;
              /* For the GPS location permissions.*/
              default: MY_PERMISSIONS_REQUEST_FINE_LOCATION:
              /* Still to be implemented .*/
                  break;
          }
      }
  </code></pre>
  
  <p>I sure appreciate any help on this. I am still new and learning Android. Thanks in advance.</p>