title: GMail for KitKat crashes on sending attachments that are not images or videos
body: <p><strong>UPDATE 3:</strong>
  Seems like all this was caused by the OTA upgrade to KitKat 4.4. Force stopping and clearing data of the GMail app fixed the issue. Not really a user-friendly result of an OTA update.</p>
  
  <p><strong>UPDATE 2:</strong>
  The crash is purely due to the new Gmail file handling in Android 4.4 KitKat. When adding any other filetype as attachment than images or video, GMail crashes upon sending the email. Why remove functionality of their app?</p>
  
  <p>Anyone know where to report GMail bugs? I can reproduce the crashes by just using GMail (not my own code):</p>
  
  <ol>
  <li><p>Compose new email</p></li>
  <li><p>Add attachment (only 2 options: "Attach Image" or "Attach Video")</p></li>
  <li><p>Select one of those.</p></li>
  <li><p>Choose a file browser (like ES file explorer) to select a zip/apk/... (or other file that is not image/video)</p></li>
  <li><p>Gmail crashes upon sending the mail.</p></li>
  </ol>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>The crash occurs on my Nexus 4 running official (OTA) KitKat.
  However, running the same code on my Samsung Galaxy S2 running CM10.2 nightly (Jelly Bean) works fine. It also works on a Samsung Galaxy Tab 2 running 4.0.4.</p>
  
  <p>Is GMail broken on KitKat?</p>
  
  <p>The Nexus 4 has GMail version 4.6.1 (920375)
  The Galaxy S2 has GMail version 4.6 (836823)</p>
  
  <p><strong>Original Question (solved, see update 3):</strong></p>
  
  <p>I have the following code in my Android application:</p>
  
  <pre><code>Intent email = new Intent(Intent.ACTION_SEND);
  email.putExtra(Intent.EXTRA_EMAIL, new String[]{"xxx@gmail.com"});
  email.putExtra(Intent.EXTRA_SUBJECT, "MetroNavigator data");
  email.setType("application/zip");
  email.putExtra(Intent.EXTRA_TEXT, "This email contains tracking data generated by the MetroNavigator app.");
  email.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
  
  startActivity(Intent.createChooser(email, "Choose a mail client to send the data:"));
  </code></pre>
  
  <p>That seems to work great, since the zip file is added to the email correctly (you can see that since GMail mentions the file size, which it doesn't if the file path is wrong).</p>
  
  <p>Screenshot: (I don't have 10 rep yet so cant embed)
  <a href="https://i.imgur.com/UkMQZLG.png" rel="noreferrer">http://i.imgur.com/UkMQZLG.png</a></p>
  
  <p>However, GMail crashes when sending the mail, giving following output:</p>
  
  <pre><code>11-23 12:22:38.451  31900-32089/? E/AndroidRuntime﹕ FATAL EXCEPTION: SyncAdapterThread-1
  Process: com.google.android.gm, PID: 31900
  java.lang.NullPointerException
          at android.content.ContentResolver.openInputStream(ContentResolver.java:613)
          at com.google.android.gm.provider.MailEngine$PublicMailStore.getInputStreamForUploadedAttachment(MailEngine.java:5591)
          at com.google.android.gm.provider.MailSync$AttachmentPartSource.newInputStream(MailSync.java:3968)
          at com.google.android.gm.provider.MailSync$AttachmentPartSource.&lt;init&gt;(MailSync.java:3941)
          at com.google.android.gm.provider.MailSync$ProtoOperationSink.messageSavedOrSent(MailSync.java:3708)
          at com.google.android.gm.provider.Operations.provideNormalOperations(Operations.java:586)
          at com.google.android.gm.provider.MailEngine$PublicMailStore.provideOperations(MailEngine.java:5290)
          at com.google.android.gm.provider.MailSync.nextSyncRequest(MailSync.java:853)
          at com.google.android.gm.provider.MailEngine.runSyncLoop(MailEngine.java:2217)
          at com.google.android.gm.provider.MailEngine.sync(MailEngine.java:2014)
          at com.google.android.gm.provider.MailEngine.performBackgroundSync(MailEngine.java:1936)
          at com.google.android.gm.provider.MailSyncAdapterService$SyncAdapterImpl.onPerformLoggedSync(MailSyncAdapterService.java:58)
          at com.google.android.common.LoggingThreadedSyncAdapter.onPerformSync(LoggingThreadedSyncAdapter.java:33)
          at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:259)
  </code></pre>
  
  <p>I've read on other questions related to attachments that you cannot upload attachment from internal storage, but I use</p>
  
  <pre><code>Environment.getExternalStorageDirectory().toString();
  </code></pre>
  
  <p>as the base for every path, and I have included </p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p>in my manifest. Also it's the GMail app that crashes and not my own. Any ideas? Is this a bug in GMail?</p>
  
  <p>Would love some input here.</p>
  
  <p>Thanks in advance,</p>
  
  <p>Thomas</p>