title: Android open pdf file
body: <p>I'm developing an Android application and I have to open some files.</p>
  
  <p>This is my code using intent:</p>
  
  <pre><code>public class FacturaActivity extends Activity {
  
      (...)
  
      public void downloadInvoice(View view) {
          File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ filename);
          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>File is in the root directory of the SD card and I can manually open it.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>Application is closed when it arrives at startActivity(intent). I think the problem is in AndroidManifest.xml file, but I don't know how to put it correctly.</p>
  
  <p><strong>AndroidManifest.xml</strong></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
  &lt;uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="8" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme"
      android:name="###.MyApplication" &gt; &lt;!--cant show complete name--&gt;
      &lt;activity
          android:name="###.MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;activity 
          android:name=".FacturaActivity" &gt;
      &lt;/activity&gt;
  
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>LogCat</strong></p>
  
  <pre><code>07-03 15:49:13.094: E/AndroidRuntime(1032): FATAL EXCEPTION: main
  07-03 15:49:13.094: E/AndroidRuntime(1032): java.lang.IllegalStateException: Could not execute method of the activity
  (...)
  07-03 15:49:13.094: E/AndroidRuntime(1032): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/201209_F2012212782.PDF typ=application/pdf flg=0x40000000 }
  07-03 15:49:13.094: E/AndroidRuntime(1032):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
  07-03 15:49:13.094: E/AndroidRuntime(1032):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
  07-03 15:49:13.094: E/AndroidRuntime(1032):     at android.app.Activity.startActivityForResult(Activity.java:2817)
  07-03 15:49:13.094: E/AndroidRuntime(1032):     at android.app.Activity.startActivity(Activity.java:2923)
  </code></pre>
  
  <p>Can you help me to complete AndroidManifest? Or how can I open that pdf?</p>