title: Android opening a file with ACTION_GET_CONTENT results into different Uri's
body: <p>I am trying to open files by using <code>Intent.ACTION_GET_CONTENT</code>. 
  <a href="https://i.stack.imgur.com/J3Aoy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/J3Aoy.png" alt="Android file browser"></a></p>
  
  <p>Dependent on the Android version/device brand the file browser opens and I get the following results:</p>
  
  <p>Selecting a file from <code>Downloads</code>:</p>
  
  <pre><code>content://com.android.providers.downloads.documents/document/446
  </code></pre>
  
  <p>Selecting a file from <code>Fotos</code>:</p>
  
  <pre><code>content://media/external/images/media/309
  </code></pre>
  
  <p>Selecting a file from <code>FileCommander</code>:</p>
  
  <pre><code>file:///storage/emulated/0/DCIM/Camera/20141027_132114.jpg
  </code></pre>
  
  <p>I can open all these files except when I try to open a file from <code>Downloads,</code>, <code>Audio</code> , <code>Afbeeldingen</code>(Images) </p>
  
  <p>It's likely I can't handle this kind of Uri: <code>content://com.android.providers.downloads.documents/document/446</code></p>
  
  <p>I have tried the following things:</p>
  
  <ul>
  <li>Trying to open the file by new File(uri.getPath()). File.exists() returns false.</li>
  <li>Trying to open/reach the file by getContext().getContentResolver().openInputStream(uri). Results into a FileNotFoundException</li>
  <li><p>Trying to open the file with the following code:</p>
  
  <pre><code>public static String getRealPathFromURI_API19(Context context, Uri uri) {
  
  Log.i("uri", uri.getPath());
  String filePath = "";
  if (uri.getScheme().equals("file")) {
      return uri.getPath();
  } else if (DocumentsContract.isDocumentUri(context, uri)) {
      String wholeID = DocumentsContract.getDocumentId(uri);
      Log.i("wholeID", wholeID);
      // Split at colon, use second item in the array
      String[] splits = wholeID.split(":");
  if (splits.length == 2) {
      String id = splits[1];
  
          String[] column = {MediaStore.Images.Media.DATA};
      // where id is equal to
          String sel = MediaStore.Images.Media._ID + "=?";
          Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                  column, sel, new String[]{id}, null);
          int columnIndex = cursor.getColumnIndex(column[0]);
          if (cursor.moveToFirst()) {
              filePath = cursor.getString(columnIndex);
          }
          cursor.close();
      }
  } else {
      filePath = AttachmentUtils.getPath(context, uri);
  }
  return filePath;
  }
  </code></pre></li>
  </ul>
  
  <p>What am I doing wrong?</p>
  
  <p>UPDATE:
  I have noticed that the files that are listed in the screenshot that they are not physically existing in the storage.
  The device I am using is a tablet from the company containing rubbish data. My colleague told me that this device once was connected with a different Google account. These files could be the files from the previous account which are not existing/reachable anymore.</p>
  
  <p>My own conclusion about it is that I am encountering some bug in Android.
  My <a href="https://code.google.com/p/android/issues/detail?id=204636&amp;thanks=204636&amp;ts=1458571718" rel="noreferrer">bug report</a></p>
  
  <h2>Update 6 february 2017:</h2>
  
  <p>Android banned the <code>file://</code> URI. Please consider to think about it.</p>
  
  <blockquote>
    <p>Ban on file: Uri Scheme The biggest compatibility issue so far with
    Android 7.0 is that the file: scheme for Uri values is banned, in
    effect. If you attempt to pass a file: Uri in an Intent that is going
    to another app — whether via an extra or as the “data” facet of the
    Intent — you will crash with a FileUriExposedException exception. You
    will face similar issues with putting file: Uri values on the
    clipboard in ClipData . This is coming from an updated edition of
    StrictMode . StrictMode.VmPolicy.Builder has a
    penaltyDeathOnFileUriExposure() method that triggers the detection of
    file: Uri values and the resulting FileUriExposedException exceptions.
    And, it appears that this is pre-configured, much as how StrictMode is
    pre-configured to apply penaltyDeathOnNetwork() (the source of your
    NetworkOnMainThreadException crashes).</p>
  </blockquote>