title: how to open files using intent action with latest Android storage framework?
body: <p>Since Android introduced major changes in storage framework recently much of the documentation talks about permissions and scoped storage. But I couldn't find details on how to process Uri of a file, for it to be readable by other apps.</p>
  <p>The intent action to view/read a file by other apps fail. I don't understand what's the problem here;</p>
  <ol>
  <li>Does it have to do with <a href="https://developer.android.com/reference/java/io/File" rel="nofollow noreferrer">difference</a> between <code>java.io.File</code> and <code>java.nio.File</code>?</li>
  <li>The Uri has missing permissions or the Uri is not well formatted.</li>
  </ol>
  <p>The Android <a href="https://github.com/android/storage-samples" rel="nofollow noreferrer">storage samples</a> (FileManager) has this bug as well. It lists all the files in a directory successfully but can't open a selected image, or a document. I've <a href="https://github.com/android/storage-samples/issues/61" rel="nofollow noreferrer">reported this issue</a> but no help so far.</p>
  <p>Following snippet is from FileManager (storage-samples)</p>
  <pre><code>fun openFile(activity: AppCompatActivity, selectedItem: File) {
      // Get URI and MIME type of file
      val uri = Uri.fromFile(selectedItem).normalizeScheme()
      val mime: String = getMimeType(uri.toString())
  
      // Open file with user selected app
      val intent = Intent()
      intent.action = Intent.ACTION_VIEW
      intent.data = uri
      intent.type = mime
      return activity.startActivity(intent)
  }
  </code></pre>