title: Sending an email with attachments programmatically on Android
body: <p>I wish to implement a button that upon pressing it will open the default email client with an attachment file.</p>
  
  <p>I am following <a href="https://stackoverflow.com/questions/20355870/explicit-intent-for-android-default-email-client">this</a>, but am getting an error message on the startActivity, saying it is expecting an activity param while I am giving it an intent.
  I am using API 21 and Android Studio 1.1.0, so perhaps it has something to do with the comment in the answer provided in the link?</p>
  
  <p>This is my fourth day as Android developer so sorry if I am missing something really basic.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    public void sendFileToEmail(File f){
  
      String subject = "Lap times";
      ArrayList&lt;Uri&gt; attachments = new ArrayList&lt;Uri&gt;();
      attachments.add(Uri.fromFile(f));
      Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
      intent.putExtra(Intent.EXTRA_SUBJECT, subject);
      intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
      intent.setClassName("com.android.email", "com.android.mail.compose.ComposeActivity");
  
      try {
          startActivity(intent);
      } catch (ActivityNotFoundException e) {
          e.printStackTrace();
      }
  </code></pre>