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

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.

write down with INTENT
intent.setPackage("com.android.mms");
instead of
intent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");

You can do...
Keep trying that approach, but catch the ActivityNotFoundException.
If you get a ActivityNotFoundException, try to launch other apps that user may have installed (VZMessages, Zlango Messaging, Handcent, ChompSMS, etc).
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.

Related

Opening link using Intent.ACTION_VIEW caused android.content.ActivityNotFoundException on certain device(s)

Recently I started getting android.content.ActivityNotFoundException: for my app logged on Google Play Console. Codes causing this exception are :
private void openLink(String url) {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
Now the exception is rarely happened, it works fine on most of devices, and the url is 100% valid (a link to https://mathsolver.microsoft.com/).
My question is what caused them and what is the best way to handle them.
Is a simple try catch enough or there is way so that user that catch this exception can still open the url from their phone?
Whenever you are starting an activity that is from another app — such as a Web browser — you have to take into account that the user might not have access to such an app. Even something as common as a Web browser might be restricted on some devices (e.g., devices used by children).
As such, you need to wrap such startActivity() calls in a try/catch block and deal with ActivityNotFoundException. Exactly how you deal with it will be up to your app, but you will need to explain to the user that you are unable to start the desired app for some reason.

sending sms intent with multiple types of extras

So I have an app that has a button where when you click it the sms app opens and a body populates which you can then send to whoever. I am using:
Intent shareIntent = new Intent(Intent.ACTION_VIEW);
shareIntent.putExtra("sms_body", getResources().getString(R.string.sharingSMS));
shareIntent.setType("vnd.android-dir/mms-sms");
startActivity(shareIntent);
This works on almost all phones I have tried it on but on the Motorola Razr (Which annoys me since I have had many problems with their code being different) the sms body is blank. Now, when I use:
shareIntent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.sharingSMS));
instead of sms_body it works fine but doesn't work with any other phones. After searching around for issues on this I found that since sms_body is not part of the android OS specifically it doesn't have to work with all phones. When I search around for how to send an sms also everything says to do it the first way I do it with sms_body.
Another thing I tried was to add both extras, then it worked on all the phones I tested it on but other people have gotten a crash with the following:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW typ=vnd.android-dir/mms-sms (has extras) }
By searching for things what I found seems like this error occurs because I have both extras attached and it tries to find things to do with both and can't find the second when it already uses one, but I'm not sure about that. In the end what I am trying to do is find something that will work with all phones or a way to use both extras without the crash. I have been looking around for a while and have found similar questions on multiple places but none of them have been answered, so any help would be great.
After playing with it I found that you can just use things for different phones. I used this code to find out what phone it is:
String manuModel = Build.MANUFACTURER + " " + Build.MODEL;

Handle Intent VIEW typ=audio/mpeg

So idea is i am opening a file using apps that are already pre-installed on the device.
Here is my code
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(fileUri);
intent.setType(mimeType);
startActivity(intent);
And my error message is
08-25 12:50:32.900: E/AndroidRuntime(19555): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW typ=audio/mpeg }
Any ideas how to approach this? I read about intent filters, but the guy from here told me that if I am going to use other apps to open my files then I don't need to specify any filters, is it true?
P.S. for some reason it opens PDF files just fine, and JPG and TXT
Thanks
Dennis xx
Any ideas how to approach this?
Install an app on your phone that has an activity that handles this MIME type. Not every possible MIME type will be handled by the apps already on your device.
If you think that such-and-so app on your device ought to be able to handle this, use AppXplore to examine its manifest and see where you are going wrong (e.g., fileUri is using an unsupported scheme).
Check the supported media formats here. Make sure you are using one of those.

notify installation complete from service

I have this piece of code
private void initiateInstallation() {
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File("/sdcard/example.apk"));
intent.setDataAndType(uri, "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
that from within my service installs an application named example.apk
I want after the installation is finished to run an activity which notifies the user about the installation.I did that except the activity appears before the installation finishes.
The problem is that within a service I cannot use startActivityForResult. So, I need a way around this so that I can start my notification activity(or for the sake of example just print something out with Toast within the service) only AFTER the installation is complete.
I already tried some answers from other questions like "alternative to startActivityforResult in services" but still I couldn't figure this out.
I also put the code so that maybe there may be something done in there.
Thanks in advance ... any suggestions are welcome.
You could listen to the PACKAGE_ADDED broadcast intent: http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_ADDED
As far as I know, these are sent after the installation is done, and you can listen to those from the service.
Just note that if the application was already installed, you will get ACTION_PACKAGE_CHANGED (as far as I know).
Also you must know the package name as well, not just the apk name, since the intent will contain the package name.
The answer given by #Pal Szasz is technically correct (as far as I know ;-) ).
However, based on the information given in your question, I assume you only wish to show a notification (no further programmatically actions are to be performed). If my assumptions are correct I would respectfully advise you NOT to show such a notification. And this is why:
The Android system already has a standard means of passing notifications to the user. The status bar will in this case already show you a message saying that the new app is successfully installed (or not installed in case of an error). If you implement yet another notification channel you will most likely confuse or irritate your users by diverging from the standard, expected behaviour.
Taking this beyond the borders of sanity one could also argue for the fact that you in some sense also would contribute to the fragmentation of Android (in a very small scale, but nevertheless).

Determine whether a device could launch Android Market app or not

I just wanted to "help" my users to give feedback to my app by providing a button to launch Market. Found a working solution here, of course, which does:
Uri uri = Uri.parse("market://details?id=<mypackagename>");
Intent intent = new Intent (Intent.ACTION_VIEW, uri);
startActivity(intent);
Simple as that, thanks!
But: on my first run, I had that on my emulator. Gives an ActivityNotFoundException immediately.
Now, my question: is there a way to find out whether a call to this intent will succeed BEFORE I try it? That way I could hide the button completely to not even give the option.
Thanks for your much appreciated help!
Instead of using this URL, you can use this one:
https://market.android.com/details?id=<mypackagename>
Even if the user doesn't have the Market application, he could go to the Website.
If he has the Market application, he should have a prompt between Internet and Market.
BTW, surround your code with a try catch in case he has nothing ;o)
You can also use this method.
Instead of IMDB, use your market URL: market://details?id=<mypackagename>
The exception was thrown just because there is no Android Market on the emulators. Every Android-powered device has the Android Market, so you shouldn't worry about this exception being thrown on a real device. Hope this helps.

Categories

Resources