title: Android: Not able to open csv file which is downloaded from DownloadManager
body: <p>I'm trying to open the <strong>CSV</strong> file downloaded using <code>DownloadManager</code> using the apps available in the phone. But I am not able to open it. The third party apps returns giving error <strong>Toast messages</strong> or <strong>Alert Dialog</strong> saying file location not found. But when, I open file manually, the app is getting opened normally. 
  I have written below code for accessing the downloaded file and opening using Intent Chooser. </p>
  
  <pre><code>fun openDownloadedFile(referenceId : Long){
      if (downloadReference === referenceId)
      {
          val query = DownloadManager.Query()
          query.setFilterById(downloadReference)
          var downloadManager = activity?.getSystemService(DOWNLOAD_SERVICE) as DownloadManager?
          val c = downloadManager?.query(query)!!
          if (c.moveToFirst())
          {
              val columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS)
              if (DownloadManager.STATUS_SUCCESSFUL === c.getInt(columnIndex))
              {
                  var localUri:String = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))
                  if (localUri.substring(0, 7).equals("file://")) {
                      localUri =  localUri.substring(7);
                  }
                  var file = File(localUri);
                  val fileExtension = MimeTypeMap.getFileExtensionFromUrl(localUri)
                  var mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension)
                  if (mimeType != null)
                  {
                      mimeType = "text/csv" // even after removing manual mime type it is not working.  
                      var intent =  Intent(Intent.ACTION_VIEW);
                      //var file = File(localUri);
                      var absoluteFilePath = file.getAbsolutePath();
                      var uri = Uri.parse( "content:/"+absoluteFilePath);
                      intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
                      intent.setDataAndTypeAndNormalize(uri, mimeType);
                      try
                      {
                          // Add chooser to open file.
                          var intentChooser = Intent.createChooser(intent, "Choose Application");
                          startActivityForResult(intentChooser,1000);
                      }
                      catch (e:ActivityNotFoundException) {
                      }
                  }
              } else {
                  Log.d(“TAG”, "Download Failed.. status : "+c.getInt(columnIndex))
              }
          }
      }
  }
  </code></pre>
  
  <p>When I chose, Microsoft Excel, it shows Cant open file error. 
  Any help is appreciated. </p>