title: BitmapFactory: Unable to decode stream: java.io.FileNotFoundException:open failed: EACCES (Permission denied) on Android Q
body: <p>I granted permissions but <code>BitmapFactory.decodeFile()</code> returns this error:</p>
  
  <pre><code>E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/IMG_20200130_165131.jpg: open failed: EACCES (Permission denied)
  </code></pre>
  
  <p>I want to take the last image from the gallery and save it to another file. I tested it on the Android P test device it was running on. But it returns this error in android emulator with android version Q (API level 29). What's wrong with that?</p>
  
  <p>These are my code snippets:</p>
  
  <pre><code>writeStoragePermissionGranted();
  
  BitmapFactory.Options options = null;
  Bitmap bm = null;
  
  String[] projection = new String[]{
              MediaStore.Images.ImageColumns._ID,
              MediaStore.Images.ImageColumns.DATA,
              MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
              MediaStore.Images.ImageColumns.DATE_TAKEN,
              MediaStore.Images.ImageColumns.MIME_TYPE,
              MediaStore.Images.ImageColumns.DISPLAY_NAME,
      };
  
      final Cursor cursor = this.getContentResolver()
              .query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null,
                      null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
        if (cursor.moveToFirst()) {
          final ImageView imageView = (ImageView) findViewById(R.id.pictureView);
          String imageLocation = cursor.getString(1);
          File imageFile = new File(imageLocation);
  
          if (imageFile.exists()) {
              options = new BitmapFactory.Options();
              options.inSampleSize = 2;
  
              try {
                      bm = BitmapFactory.decodeFile(imageLocation, options);
              } catch(Exception e) {
                      e.printStackTrace();
              }
          }
  
          imageView.setImageBitmap(bm);
  
  
  
          try {
              saveImage(bm,"NAME" );
          } catch (IOException e) {
                  e.printStackTrace();
          }
      }
  </code></pre>
  
  <p><code>writeStoragePermissionGranted()</code> function:</p>
  
  <pre><code> public void writeStoragePermissionGranted() {
         if (Build.VERSION.SDK_INT &gt;= 23) {
             if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
                     == PackageManager.PERMISSION_GRANTED) {
              startPeriodicRequest();
          } else {
              ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Constants.REQUEST_CODE_WRITE_EXTERNAL_STORAGE_PERMISSION);
          }
      } else {
          return;
      }
  } 
  </code></pre>
  
  <p>and manifest permissions:</p>
  
  <pre><code> &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
   &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p>I know there are many question about that. But no one worked on the android emulator version Q. On the other hand, this code works on android pie (API level 28)</p>