在 Android 设备上发送带有 vCard 附件的彩信
我正在尝试找到一种方法来发送包含 vCard 附件 的彩信。我认为这将是一项相当简单的任务,但我仍然没有想出可以在各种 Android 手机上运行的东西。
我尝试的第一件事是:
定义一个意图,显示能够发送 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."));
使用此功能时,我注意到以下内容:
- 在三星 Galaxy S 上,选择器允许我选择蓝牙、Gmail 和消息应用程序。使用消息应用程序时,存在附件和文本,我可以发送彩信。我在旧的索尼爱立信手机(Android 之前的版本)上处理彩信,并且 vCard 处理得很好。
- 在 Google Nexus S 和 Motorola DroidX 上,选择器只允许我选择蓝牙和 Gmail。 (选择器中缺少消息应用程序)。
(我的结论):看来Android并没有附带能够满足此处指定的Intent的库存应用程序。 (没有应用程序允许使用 text/x-vcard mimeType)。 Galaxy S 配备了自己的消息应用程序,能够处理 vcard mimetype。
一切都很好,但是我们如何着手解决这个问题呢?
我尝试了以下方法:
通过指定类直接启动消息传递意图
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);
使用此代码,可以直接启动消息传递应用程序。选择这种方法是因为它至少允许我们在 Nexus S 上弹出消息应用程序(在使用选择器之前,消息应用程序不存在)。
在 Samsung Galaxy S 上,附件将添加到彩信撰写屏幕上并正确发送。 在 Google Nexcus S 上,附件不存在。
从 Intent 中删除 mimeType 时,消息应用程序会弹出不支持的媒体类型错误消息。
所以问题是:是否有一段简单且统一的代码可以让您发送带有 vCard 附件的彩信?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论