title: Show PDF in Android
body: <p>In my onCreate() I do this check:</p>
  
  <pre><code>//
  // check if we have a PDF viewer, else bad things happen
  //
  Intent intent = new Intent(Intent.ACTION_VIEW);
  intent.setType("application/pdf");
  
  List&lt;ResolveInfo&gt; intents = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
  
  if (intents == null || intents.size() == 0) {
         // display message then...
         finish();
  }
  </code></pre>
  
  <p>On my HTC Desire, this doesn't return a match, even though I have Adobe's PDF viewer. An answer to this question <a href="https://stackoverflow.com/questions/2916108/android-open-a-pdf-from-my-app-using-the-built-in-pdf-viewer">android: open a pdf from my app using the built in pdf viewer</a> mentions that Adobe may not have any public Intents, so the above check will obviously return nothing.</p>
  
  <p>Can anyone verify whether you should be able launch Acrobat from an intent, or is there some other method or PDF viewer to use.</p>
  
  <p>The actual use case is downloading copies of invoices and storing them on local storage using code such as:</p>
  
  <pre><code> URL url = new URL(data);
   InputStream myInput = url.openConnection().getInputStream();
  
   FileOutputStream fos = openFileOutput(fname, Context.MODE_WORLD_READABLE);
  
   // transfer bytes from the input file to the output file
   byte[] buffer = new byte[8192];
   int length;
   while ((length = myInput.read(buffer)) &gt; 0) {
      fos.write(buffer, 0, length);
      progressDialog.setProgress(i++);
   }
   fos.close();
  </code></pre>
  
  <p>and then to show</p>
  
  <pre><code>// read from disk, and call intent
  openFileInput(fname);   // will throw FileNotFoundException
  
  File dir = getFilesDir();       // where files are stored
  File file = new File(dir, fname);   // new file with our name
  
  Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
  intent.setType("application/pdf");
  
  startActivity(intent);
  </code></pre>