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.
Related
Issue:
I've been working on an app that listens to a certain kind of intents depending on a given link format. My intent filter works as expected, I'm just wondering whether it's possible to force the android system to bypass the kind of dialog below and open only my app.
I'm just wondering whether it's possible to force the android system to bypass the kind of dialog below and open only my app.
Do you own the domain of the URI that is being invoked? If so, than yes, with app links.
If not, then no.
you force user to use a specific browser by this:
String packageName = "com.android.yourBrowser";
String className = "com.android.browser.YourBrowserActivity";
Intent internetIntent = new Intent(Intent.ACTION_VIEW);
internetIntent.addCategory(Intent.CATEGORY_LAUNCHER);
internetIntent.setClassName(packageName, className);
The following code works most of the time:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/internal/images/media"));
startActivity(intent);
It throws the following exception sometimes (reported by error log from users):
android.content.ActivityNotFoundException: No Activity found to handle Intent {
act=android.intent.action.VIEW
dat=content://media/internal/images/media }
Stack trace:
android.content.ActivityNotFoundException: No Activity found to handle
Intent { act=android.intent.action.VIEW
dat=content://media/internal/images/media } at
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1899)
at
android.app.Instrumentation.execStartActivity(Instrumentation.java:1589)
at android.app.Activity.startActivityForResult(Activity.java:4228)
at android.support.v4.app.k.startActivityForResult(SourceFile:50) at
android.support.v4.app.p.startActivityForResult(SourceFile:79) at
android.app.Activity.startActivityForResult(Activity.java:4187) at
android.support.v4.app.p.startActivityForResult(SourceFile:859) at
android.app.Activity.startActivity(Activity.java:4515) at
android.app.Activity.startActivity(Activity.java:4483)
I am wondering if some users' Android devices do not have Gallery.
I am wondering if some users' Android devices do not have Gallery.
There is no requirement for any Android device to have any exported activity that supports that particular Intent structure (ACTION_VIEW for whatever MIME type is tied to that Uri, plus a content scheme).
Beyond that, there is no single app named "Gallery". Out of ~2 billion devices and ~10,000 device models, there may be hundreds of apps that serve this general role, and a device might not have any such app.
What is a reliable way to open Gallery on Android?
See CATEGORY_APP_GALLERY, and be sure to handle the case where there is no matching activity.
I am looking to start a specific application(Dictionary app) from my app. Using intents, how would I go about launching that specific app and use it to look up the word.
There are implicit intents and explicit intents, you want an explicit intent to get your desirable.
Here is how you can do it.
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example", "com.example.MyExampleActivity"));
startActivity(intent);
in the setComponent method your Dictionary app information should go in.
CommonsWare addition to this answer,
Using an explicit Intent to talk to a third-party app is rarely the right thing to do. This code will break if the activity is not exported, or requires permissions, or the developer refactors the code and changes the class name or package, etc.
If the author of the app is documenting that your recipe is the correct way to work with that activity on that app, then that is fine, as the developer presumably intends to support this use case.
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.
I have included a file called "Manual.pdf" in my assets folder. I have created a menu button called "Help". I want the user to be able to go to the menu, press on the Help button, and launch the Manual.pdf file in whatever viewer the phone has installed.
I have read for a few hours on this site and other sites, but I just can't get the file to launch.
Thanks for any help.
There is no unified PDF reader for Android Devices. I assume that in the course of your research you would have found that, you could use an implicit intent to invoke a pdf reader if it does exists.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
intent.setType("application/pdf");
It works in some devices and fails in some other devices. ( so please check availability of intent using the package manager). If you are targeting a particular device then you could get the corresponding Activity Object and use an Implicit Intent.(com.htc.pdfreader for HTC Phones).