将 MMS 意图与图像文件结合使用
所以我试图调用一个将图片附加到短信的意图。以下代码在模拟器上正确显示带有图像的文本消息窗口,但在我的手机(Droid X)上崩溃了。
String name = FILE_NAME;
Uri uri = Uri.fromFile(new File(name));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
startActivity(intent);
。
12-30 12:56:50.628: ERROR/AndroidRuntime(14603): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.mms/com.android.mms.ui.ComposeMessageActivity}; have you declared this activity in your AndroidManifest.xml?
问题是 .setClassName 行。我将值硬编码到类中,这可能是错误的。我应该在这里使用什么来支持所有手机?
谢谢大家。
So I am trying to invoke an intent that will attach a picture to a text message. The following code correctly brings up a text message window with the image on the emulator, but crashed on my phone (Droid X).
String name = FILE_NAME;
Uri uri = Uri.fromFile(new File(name));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
startActivity(intent);
.
12-30 12:56:50.628: ERROR/AndroidRuntime(14603): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.mms/com.android.mms.ui.ComposeMessageActivity}; have you declared this activity in your AndroidManifest.xml?
The problem is the .setClassName line. I hardcoded the value to the class, which is probably wrong. What should I be using here to support all phones?
Thanks all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根本不要设置类名。这将使 Android 找到最适合您的活动,并在必要时启动应用程序选择器对话框。
另一种方法是解决意图的所有可能活动,并使用一些逻辑来确定您更喜欢哪一个,如果您的逻辑无法选择一个,则默认让 Android 选择。但这有点过分了,如果您的目标只是让用户发送彩信,则不需要那么详细。
Do not set the class name at all. This will cause Android to find the best possible activity for you, launching the app chooser dialog if necessary.
An alternative would be to resolve all possible activities for the intent and use some logic to determine which one you prefer, and default to letting Android choose if your logic can't pick one. That's a little over the top though, and if your goal is just to let the user send an MMS there's no need for that level of detail.
sendIntent.setPackage("com.android.mms");
这将解决你的问题
sendIntent.setPackage("com.android.mms");
that will solve your issue