GMail for KitKat crashes on sending attachments that are not images or videos

android, android-intent, gmail, nullpointerexception

Solution

Like mentioned in Update 3 of my original question, the culprit is a corrupt gmail app. Clearing data fixes the issue.

Problem

UPDATE 3: 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. UPDATE 2: 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? Anyone know where to report GMail bugs? I can reproduce the crashes by just using GMail (not my own code): Compose new email Add attachment (only 2 options: "Attach Image" or "Attach Video") Select one of those. Choose a file browser (like ES file explorer) to select a zip/apk/... (or other file that is not image/video) Gmail crashes upon sending the mail. UPDATE: 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. Is GMail broken on KitKat? The Nexus 4 has GMail version 4.6.1 (920375) The Galaxy S2 has GMail version 4.6 (836823) Original Question (solved, see update 3): I have the following code in my Android application: ``` 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:")); ``` 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). Screenshot: (I don't have 10 rep yet so cant embed) https://i.stack.imgur.com/gafSc.png However, GMail crashes when sending the mail, giving following output: ``` 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.<init>(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) ``` I've read on other questions related to attachments that you cannot upload attachment from internal storage, but I use ``` Environment.getExternalStorageDirectory().toString(); ``` as the base for every path, and I have included ``` <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> ``` in my manifest. Also it's the GMail app that crashes and not my own. Any ideas? Is this a bug in GMail? Would love some input here. Thanks in advance, Thomas

Original source