Android:尝试在特定设备上发送彩信时偶尔会遇到 ActivityNotFoundException

发布于 2024-12-11 19:13:52 字数 1155 浏览 0 评论 0原文

我正在使用精彩的 ACRA 库来报告用户在我的应用程序测试版中遇到的任何错误。到目前为止所显示的是,一些用户在发送彩信时遇到问题,而大多数用户则没有。 特别是,我发现使用 Droid Bionic 设备的用户遇到了此错误,但当我在本地运行 Droid Bionic 模拟器时,没有遇到问题。 我用来启动彩信活动的代码是...

File imageFile = new File(getContext().getFilesDir() + File.separator + fileName);
Uri uri = Uri.fromFile(imageFile);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
sendIntent.putExtra("sms_body", ""); 
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("image/png");
getContext().startActivity(sendIntent);

我看到的错误 - 只是偶尔 - 是:

android.content.ActivityNotFoundException:无法找到显式活动类 {com.android.mms/com.android.mms.ui .ComposeMessageActivity};您是否在 AndroidManifest.xml 中声明了此活动?

我怀疑某些运营商可能修改了 Android 并覆盖/禁用了默认的彩信活动。我真的没有一个好的方法来测试这个,因为我亲自测试过的所有物理设备和运营商都没有这个代码的问题。正如我所提到的,Droid Bionic 模拟器工作正常,但它是该领域存在问题的设备之一。

我想知道是否有人经历过类似的事情并有建议的解决方法?或者,如果有人有一种在 Android 上发送彩信的方法,适用于所有设备/运营商。

(现在我只是捕获异常并让用户知道我无法使用他们的设备发送彩信。)

ps 我在另一个论坛中看到有人建议删除意图的类名。问题是,当你这样做时,所有各种类型的应用程序都说它们可以处理意图(例如 Evernote),而事实上我真的只想要彩信或什么都不想要。

I am using the wonderful ACRA library to report any errors that users experience with the beta version of my app. What it has shown so far is that some users experience problems sending MMS messages, while most do not.
In particular I found that a user using a Droid Bionic device experienced this error, but when I run the Droid Bionic emulator locally, I have don't have a problem.
The code I use to start the MMS activity is...

File imageFile = new File(getContext().getFilesDir() + File.separator + fileName);
Uri uri = Uri.fromFile(imageFile);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
sendIntent.putExtra("sms_body", ""); 
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("image/png");
getContext().startActivity(sendIntent);

The error I see - only very occasionally - is :

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?

My suspicion is that perhaps certain carriers have modified Android and overridden/disabled the default MMS activity. I don't really have a good way of testing this as all the physical devices and carriers I have personally tested it on have no problem with this code. And as I mentioned, the Droid Bionic emulator works fine, but it was one of the devices in the field that had a problem.

I'm wondering if anyone has experienced something similar and has a suggested workaround? Or if someone has a method for sending MMS on Android that works on all devices/carriers.

(For now I am just catching the exception and letting the user know that I couldn't send MMS with their device.)

p.s. I saw in another forum someone suggesting just removing the classname for the intent. The problem with that is when you do that all and sundry types of applications say they can handle the intent (e.g Evernote) when in fact I really just want MMS or nothing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

盛夏已如深秋| 2024-12-18 19:13:52

写下意图

intent.setPackage("com.android.mms");

而不是

intent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");

write down with INTENT

intent.setPackage("com.android.mms");

instead of

intent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
£冰雨忧蓝° 2024-12-18 19:13:52

您可以做...

  1. 继续尝试该方法,但捕获 ActivityNotFoundException。
  2. 如果您收到 ActivityNotFoundException,请尝试启动用户可能已安装的其他应用程序(VZMessages、Zlango Messaging、Handcent、ChompSMS 等)。
  3. 如果所有这些都失败,请让您的用户知道您要发送彩信,然后启动意图而不指定类。这样,用户就可以选择实际发送彩信的应用程序。

You can do...

  1. Keep trying that approach, but catch the ActivityNotFoundException.
  2. If you get a ActivityNotFoundException, try to launch other apps that user may have installed (VZMessages, Zlango Messaging, Handcent, ChompSMS, etc).
  3. If all of them fail, let your user know that you want to send a MMS, and then launch the intent without specifying the class. That way it is up to the users to choose an app that actually send MMS messages.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文