title: Android 11 Media store - cannot record new videos on relative path. It works with Environment.DIRECTORY_MOVIES path but not not with sub folder
body: <p>My code runs perfect on any Android lower then Android 11.
  On Android 11 (specifically on Pixel2 &amp; Pixel3 emulator and real devices) the file descriptor fail to find the file after inserting it to the media store.</p>
  <p>If I change the relative path on the second line to be only the Environment.DIRECTORY_MOVIES path - it works</p>
  <pre><code>String relativeLocation = Environment.DIRECTORY_MOVIES;
  </code></pre>
  <p>This is my code:</p>
  <pre><code>String mimeType = &quot;video/mp4&quot;;
  String relativeLocation = Environment.DIRECTORY_MOVIES + File.separator + SUB_DIRECTORY_NAME ;
  shortFileName = getDateStamp() + selectedExtension;
  videoContentValues = new ContentValues();
  videoContentValues.put(MediaStore.Video.Media.TITLE, shortFileName);
  videoContentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, shortFileName);
  videoContentValues.put(MediaStore.MediaColumns.MIME_TYPE, mimeType);
  videoContentValues.put(MediaStore.Video.Media.DATE_ADDED, System.currentTimeMillis() / 1000);
  videoContentValues.put(MediaStore.Video.Media.DATE_TAKEN, System.currentTimeMillis());
  
  videoContentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, relativeLocation);
  videoContentValues.put(MediaStore.MediaColumns.IS_PENDING, 1);
  videResolver = mContext.getContentResolver();
  
  Uri contentUri = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
  videoUri = videResolver.insert(contentUri, videoContentValues);
  if (videoUri == null) {
      throw new IOException(&quot;Failed to create new MediaStore record.&quot;);
  }
  pfd = mContext.getContentResolver().openFileDescriptor(videoUri, &quot;w&quot;);
  mMediaRecorder.setOutputFile(pfd.getFileDescriptor());
  </code></pre>
  <p>The code runs OK until it gets to the openFileDescriptor which return the following error:</p>
  <pre><code>java.io.FileNotFoundException: java.io.FileNotFoundException: No item at content://media/external_primary/video/media/47
  </code></pre>
  <p>What am I doing wrong?</p>
  <p>Update 1:
  More info:
  I am still requesting WRITE_EXTERNAL_STORAGE and making sure it is allowed before start recording</p>
  <p>The following code works in the same camera app on Android 11 Pixel 2 emulator to save pics:</p>
  <pre><code>    String mimeType = &quot;image/jpeg&quot;;
      final String relativeLocation = Environment.DIRECTORY_PICTURES + File.separator + SUB_DIRECTORY_NAME;
      ContentValues contentValues = new ContentValues();
      contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, createImageFileNameQ());
      contentValues.put(MediaStore.MediaColumns.MIME_TYPE, mimeType);
      contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, relativeLocation);
      ContentResolver resolver = mContext.getContentResolver();
      OutputStream stream = null;
      Uri uri = null;
      try {
            final Uri contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            uri = resolver.insert(contentUri, contentValues);
        try {
                  OutputStream fos = resolver.openOutputStream(uri);
                  fos.write(data);
                  fos.flush();
                      fos.close();
             }
       catch (Exception ex) {
          Log.e(TAG, ex.toString());
        }
  </code></pre>
  <p>Update 2:</p>
  <p>If I write on the second line &quot;String relativeLocation = Environment.<strong>DIRECTORY_PICTURES</strong> + File.separator + SUB_DIRECTORY_NAME;&quot; and not DIRECTORY_MOVIES :
  It works!@!!
  Video files are saved on Videos\Sub_Directory</p>
  <p>Update 3:
  Now on the emulators:</p>
  <p>no trick helps to make relative path.
  And also the pics cannot be saved to relative path</p>
  <pre><code>String mimeType = &quot;image/jpeg&quot;; String relativeLocation = Environment.DIRECTORY_PICTURES + File.separator + SUB_DIRECTORY_NAME;
  ContentValues contentValues = new ContentValues();
      
   contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, createImageFileNameQ());
    contentValues.put(MediaStore.MediaColumns.MIME_TYPE, mimeType);
    contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, relativeLocation);
  
    ContentResolver resolver = mContext.getContentResolver();
  
  
    OutputStream stream = null;
    Uri uri = null;
  
    try {
      final Uri contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
       uri = resolver.insert(contentUri, contentValues);
   try {
       OutputStream fos = resolver.openOutputStream(uri);
       fos.write(data);
       fos.flush();
       fos.close();
   } catch (Exception ex) {
   Log.e(TAG, ex.toString());
   }
   } catch (Exception e) {}
  </code></pre>