title: Unable to open PDF from internal storage for viewing on Android 8 and 9 using File Provider
body: <p>For Android 8 and 9 only. </p>
  
  <p>I have a PDF filer here - </p>
  
  <pre><code>String url = "file:///storage/emulated/0/Android/data/com.verna.poc/files/Download/mypdf.pdf";
  </code></pre>
  
  <p>I'm trying to open this file for viewing using this - </p>
  
  <pre><code>File file= new File(url);
  file.setReadable(true, false);
  
  Intent intent = new Intent(Intent.ACTION_VIEW);
  Uri pdfUri = FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID + ".provider", file);
  intent.setDataAndType(pdfUri, "application/pdf");
  intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
  
  List&lt;ResolveInfo&gt; resInfoList = getApplicationContext().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
      for (ResolveInfo resolveInfo : resInfoList) {
          String packageName = resolveInfo.activityInfo.packageName;
          getApplicationContext().grantUriPermission(packageName, pdfUri,
                  Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
      }
  
  Intent in = Intent.createChooser(intent, "Open File");
  startActivity(in);
  </code></pre>
  
  <p>The File chooser option is opening and when I open the file using Google PDF reader, the PDF reader opens and closes immediately. Whats wrong in my code ?</p>