title: Uri from Intent is different with different Devices
body: <p>I am trying to open files by using Intent.ACTION_GET_CONTENT like in this post: </p>
  
  <p><a href="https://stackoverflow.com/questions/36128077/android-opening-a-file-with-action-get-content-results-into-different-uris">Android opening a file with ACTION_GET_CONTENT results into different Uri&#39;s</a></p>
  
  <p>But here is just a solution how to get the filename with different SDKs/Folders and not for different devices. Also the Intent to get the Uri stays the same.</p>
  
  <p>I want to open .png files.</p>
  
  <p>Uri.getPath() for the both devices are (both .png files stored in the download folder):</p>
  
  <pre><code>   Samsung S3 Tablet (Android 8.0): /document/559
  
     Samsung Galaxy S7 (Android 8.0): /document/raw:/storage/0/emulated/Download/Karte1.png
  </code></pre>
  
  <p>Therefore the problem is, if i initialise an InputStream with </p>
  
  <pre><code>   getActivity().getContentResolver().openInputStream(uri)
  </code></pre>
  
  <p>its not working for the Tablet.</p>
  
  <p>Here is the Intent code snippet:</p>
  
  <pre><code>    public void browseClick() {
          Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
          intent.setType("image/png");
          intent.addCategory(Intent.CATEGORY_OPENABLE);
          try {
              startActivityForResult(Intent.createChooser(intent, 
              getString(R.string.choose_floorPlan)),REQUEST_CODE_OPEN_FILE);
          } catch (Exception ex) {
              System.out.println("browseClick :"+ex);
          }
      }
  </code></pre>
  
  <p>OnActivityResult:</p>
  
  <pre><code>    @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (requestCode != REQUEST_CODE_OPEN_FILE) {
              return;
          }
          if ((resultCode == RESULT_OK) &amp;&amp; (data != null)) {
  
              try {
                  selectedMap = data.getData();
                  String filename = FileHelper.getUriName(selectedMap, 
                  getActivity());              
  
                  textMapDir.setText(getString(R.string.placeholder_
                  folder_begin, filename));
                  textMapDir.setText(selectedMap.getPath());
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
  </code></pre>
  
  <p>In this method im using the uri and openInputStream(uri)</p>
  
  <pre><code>    private boolean createFiles(String pathProjectDir, Uri selectedMap) {
      if (!ExistsDir(pathProjectDir)) { //it should be possible to add more floors/buildings to an existing project
          if (getAndCreateDir(pathProjectDir).exists()) {
              InputStream excelFile;
              InputStream mapFile;
              try {
                  excelFile = Objects.requireNonNull(getActivity()).getAssets().open(EXCEL_FILE_NAME);
                  mapFile = getActivity().getContentResolver().openInputStream(selectedMap);
  
                  if (FileHelper.getMimeType(selectedMap.getPath()).equals("application/pdf")) {
  
                      // some code
  
                  } else if (FileHelper.getMimeType(selectedMap.getPath()).equals("image/png")) {
                      if ((copyFile(excelFile, getExcelPath(pathProjectDir)))
                              &amp;&amp; (copyFile(mapFile, getMapPathPNG(pathProjectDir)))) {
                          return true;
                      }
                  }
              } catch (IOException e) {
                  e.printStackTrace();
                  Toast.makeText(getActivity(), getString(R.string.excel_file_unable_to_create), Toast.LENGTH_LONG).show();
                  return false;
              }
          }
          Toast.makeText(getActivity(), getString(R.string.project_dir_was_not_created), Toast.LENGTH_LONG).show();
          return false;
      }
      Toast.makeText(getActivity(), getString(R.string.project_dir_exisitng), Toast.LENGTH_LONG).show();
      return false;
      }
  </code></pre>
  
  <p>Thats the getMimeType() method, where i check the MIME from the uri, that could be the problem:</p>
  
  <pre><code>    public static String getMimeType(String path) {
      String type = null;
      String extension = MimeTypeMap.getFileExtensionFromUrl(path);
      if (extension != null) {
          type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
      }
      return type;
  }
  </code></pre>
  
  <p>This is the copyFile() method where I copy the InputStream:</p>
  
  <pre><code>    public static Boolean copyFile(InputStream isFile, String pathOutput) {
      try {
          FileOutputStream fos = new FileOutputStream(new File(pathOutput));
          copyFileBuffer(isFile, fos);
          isFile.close();
          fos.flush();
          fos.close();
          return true;
      } catch (IOException io) {
          io.printStackTrace();
      }
      return false;
  }
  </code></pre>
  
  <p>To complete the code here is the copyFileBuffer() method, but this should be fine:</p>
  
  <pre><code>    public static Boolean copyFile(InputStream isFile, String pathOutput) {
      try {
          FileOutputStream fos = new FileOutputStream(new File(pathOutput));
          copyFileBuffer(isFile, fos);
          isFile.close();
          fos.flush();
          fos.close();
          return true;
      } catch (IOException io) {
          io.printStackTrace();
      }
      return false;
  }
  </code></pre>