Intent.ACTION_SEND Crashes Facebook App

I came across a rather obscure bug today, while trying to submit my app Tap That! Number to the Amazon Appstore. I received a rejection notice detailing several problems with my app, including this strange one:

Application’s “Feedback” functionality “Facebook” option is not working.

At first I had no idea what this meant. My app never mentions Facebook at all. The only “Feedback” option I have is a menu item designed to send an email to the developer.

After digging around a bit, I found that the code I was using to launch an email intent was also recognising Facebook and presenting it in the list of available apps. Here’s the code I was using:

//Launch email intent
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Tap That! Number Feedback");
startActivity(Intent.createChooser(emailIntent, "Send email ..."));

But I wrote this code following the advice of many tutorials I’ve read, and plenty of other people are using the exact same approach. So there shouldn’t be a problem, right?

Android Intent Chooser Screenshot
The Intent Chooser which appears when you select "Feedback". Note the title "Send Email..."

Well, turns out it’s actually a problem with Facebook’s app. It can’t handle receiving an Intent.ACTION_SEND unless you specify the body text. If you run the code listed above, and select “Facebook” in the Intent chooser that appears, you’ll see the Facebook app crash (force close). But if you add an extra line of code, everything will work perfectly:

//Launch email intent
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Tap That! Number Feedback");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "I've been playing Tap That! Number for Android...");
startActivity(Intent.createChooser(emailIntent, "Send email ..."));

Notice the extra line highlighted in bold? The Facebook app needs that line to be present, otherwise it will force close when handling the Intent.ACTION_SEND. Of course I never noticed this behaviour while testing my app, because I knew that the “Feedback” option was designed to send an email. I never even considered trying the Facebook option. It just goes to show how important it is to have “outsiders” thoroughly test your app. They can often find obscure bugs, which you wouldn’t have found on your own.

Facebook Force Close
The Facebook app crashes if you send an empty intent

Hopefully this bit of information will help some other developer, if you’re trying to send an email from your own app. I’ve submitted a bug report to Facebook so hopefully they’ll fix this soon. But in the mean time, we’ll have to remember this little idiosyncrasy.

If you want some more info on sending emails from Android, check out this StackOverflow topic. It’s quite helpful and covers some of the issues mentioned here.

Note: All of the other apps (Gmail, Blogger, Dropbox, Twitter, etc.) handle an empty (or, in this case, half-empty) Intent.ACTION_SEND perfectly fine. It’s only Facebook that has a problem.