简体   繁体   中英

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

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.)

ps 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 (eg Evernote) when in fact I really just want MMS or nothing.

write down with INTENT

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

instead of

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM