title: Writing EXIF data to image saved with DocumentFile class
body: <p>I need to get a File from DocumentFile or Uri with correct scheme not the one with <code>content://com.android.externalstorage.documents/tree/primary:</code> if the device's main memory is selected.
  To get File or absolute path of the image i need  the one with file:///storage/emulated/0 or storage/emulated/0 but i could not find a way to get correct Uri for building a File to write EXIF data to image.</p>
  
  <p>My scenario is:</p>
  
  <ol>
  <li>User chooses a path to save images which returns Uri  with <code>content://com.android.externalstorage.documents</code> onActivityResult(). I save this path with <code>treeUri.toString()</code> to SharedPreferences for using later.</li>
  <li>User takes a picture and image is saved with <code>DocumentFile.fromTreeUri(MainActivity.this, Uri.parse(uriString));</code></li>
  <li>This where i fail, getting a File that correctly points to image, Uri with content:// does not return the existing image.Correct Uri should <code>file:///storage/emulated/</code> and i can convert this Uri to file using <code>File filePath = new File(URI.create(saveDir.getUri().toString()));</code></li>
  </ol>
  
  <p>How can i get the Uri needed for consturcting File or File using Uri i got from SAF UI?</p>
  
  <p><strong>EDIT:</strong> <a href="https://android-developers.googleblog.com/2016/12/introducing-the-exifinterface-support-library.html" rel="nofollow noreferrer">ExifInterface Support Library</a> is introduced for Android 7.1+ that can use InputStream or FileDescriptor.</p>
  
  <pre><code>Uri uri; // the URI you've received from the other app
  InputStream in;
  try {
    in = getContentResolver().openInputStream(uri);
    ExifInterface exifInterface = new ExifInterface(in);
    // Now you can extract any Exif tag you want
    // Assuming the image is a JPEG or supported raw format
  } catch (IOException e) {
    // Handle any errors
  } finally {
    if (in != null) {
      try {
        in.close();
      } catch (IOException ignored) {}
    }
  }
  </code></pre>
  
  <p><strong>Note:</strong> ExifInterface will not work with remote InputStreams, such as those returned from a HttpURLConnection. It is strongly recommended to only use them with content:// or file:// URIs.</p>
  
  <p>Snippet above is reading data obviously since it opens an InputStream to read data. I need to be able to write EXIF data to JPEG files.</p>