title: Unable to open PDF file through intent programmatically in android
body: <p>I have an app where on button click, access should be provided to browse and open the PDF files stored in the internal memory of the device.I tried various codes but i get an toast saying "Cannot display PDF". I don't get any errors in logs. I use android version 7.0 device. Attached my code below: please help:</p>
  
  <pre><code>File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/example.pdf");
  Intent intent = new Intent(Intent.ACTION_VIEW);
  intent.setDataAndType(Uri.fromFile(file), "application/pdf");
  intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
  startActivity(intent); 
  </code></pre>
  
  <p>I have included this in Oncreate:</p>
  
  <pre><code>StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
  StrictMode.setVmPolicy(builder.build()); 
  </code></pre>
  
  <p>This is how called the method:</p>
  
  <pre><code>  linear_pdf.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              pdf.setTextColor(getActivity().getResources().getColor(R.color.colorWhite));
  
  
                              openPdf(getContext(), Environment.getExternalStorageDirectory().getAbsolutePath()+"/example.pdf");
  
  
  
                              communication.dismiss();
                          }
                      });
  </code></pre>