问题
I'm trying to find a way to send a MMS message containing a vCard attachment. I thought this would be a fairly easy task, but I still haven't managed to come up with something that just works over a wide variety of Android phones.
The first thing I tried was this :
Define an intent showing a list of apps capable of sending the vCard
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/x-vcard");
i.putExtra(Intent.EXTRA_TEXT,"MMS with vCard");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse (someFilereference);
startActivity(Intent.createChooser(i, "Select MMS application."));
When using this, I noticed the following :
- On a Samsung Galaxy S, the chooser allowed me to pick Bluetooth,Gmail and the Messaging app. When using the Messaging app, the attachment and text was present, and I could send the MMS. I processed the MMS on an old Sony Ericson phone (pre-android) and the vCard was processed fine.
- On a Google Nexus S and Motorola DroidX, the chooser only allowed me to pick Bluetooth and Gmail. (the Messaging app was missing from the chooser).
(My conclusion) : It appears that Android doesn't come with a stock application that is capable of satisfying the Intent specified here. (no app allows with the text/x-vcard mimeType). The Galaxy S comes with its own Messaging app that is capable of handling the vcard mimetype.
That's all very well, but how do we go about and solve this ?
I tried the following approach :
Launch the messaging intent directly by specifying the class
Intent intent = new Intent(Intent.ACTION_SEND);
i.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
i.setType("text/x-vcard");
i.putExtra("sms_body", "SomeText");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse (someFileRef);
startActivity(i);
Using this code, the messaging app is launched directly. This approach was choosen as it at least allows us to pop a messaging app on the Nexus S (before with the chooser, the messaging app was not present).
On the Samsung Galaxy S, the attachment is added on the MMS compose screen and is correctly sent. On the Google Nexcus S, the attachment is not present.
When removing the mimeType from the Intent, the Messaging app pops an Unsupported media type error message.
So the questions is : is there a simple and uniform piece of code that allows you to send an MMS with a vCard attachment ?
来源:https://stackoverflow.com/questions/5443654/sending-an-mms-with-a-vcard-attachment-on-android-devices