Android: ActivityNotFoundException occasionally encountered when trying to send MMS on specific devices

空扰寡人 提交于 2019-12-13 02:27:51

问题


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.


回答1:


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.



回答2:


write down with INTENT

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

instead of

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


来源:https://stackoverflow.com/questions/7880552/android-activitynotfoundexception-occasionally-encountered-when-trying-to-send

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!