title: java.io.IOException: Permission denied cannot create file
body: <p>I follow this <a href="https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en" rel="noreferrer">tutorial</a> to take photo and save into device storage, but when I execute it, it got an exception </p>
  
  <blockquote>
  <pre><code>java.io.IOException: Permission denied 
   on line:
  
  File image = File.createTempFile(imageFileName, ".jpg", storageDir);
  </code></pre>
  </blockquote>
  
  <p>How to solve this?</p>
  
  <pre><code>private File createImageFile() throws IOException
  {
      // Create an image file name
      String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
      String imageFileName = "JPEG_" + timeStamp + "_";
      File storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "Camera");
      File image = File.createTempFile(imageFileName, ".jpg", storageDir);
  
      // Save a file: path for use with ACTION_VIEW intents
      mCurrentPhotoPath = "file:" + image.getAbsolutePath();
      return image;
  }
  </code></pre>
  
  <p><strong>--Edit--</strong><br>
  Here is my manifests</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.idea.takephoto"&gt;
  
  &lt;uses-feature android:name="android.permission.CAMERA"/&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  &lt;!--&lt;uses-feature android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;--&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity android:name=".MainActivity"&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;provider
          android:name="android.support.v4.content.FileProvider"
          android:authorities="${applicationId}.provider"
          android:exported="false"
          android:grantUriPermissions="true"&gt;
          &lt;meta-data
              android:name="android.support.FILE_PROVIDER_PATHS"
              android:resource="@xml/provider_paths"/&gt;
      &lt;/provider&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>