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.
Related
I add a live wallpaper feature in our app, but got some exception in firebase. I tested on our ten android devices and got no exception, I wonder if I can determine live wallpaper is supported in a specific device programmatically (I don't want to filter devices in Google Play Console, as it kick out tow much devices)? thanks.
Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.service.wallpaper.CHANGE_LIVE_WALLPAPER (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2067)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1727)
at android.app.Activity.startActivityForResult(Activity.java:5383)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java)
at android.app.Activity.startActivityForResult(Activity.java:5341)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java)
may be you could check if an activity is available before starting the intent.
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent);
}
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.
I am using this quite simple piece of code to capture an image on an Android device.
File tmpFile = ...;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tmpFile));
startActivityForResult(intent, CAPTURE_IMAGE);
This works fine for thousands of users except for one running this on a Kindle device without camera. Today I got a crash report from a device with camera:
ANDROID_VERSION=4.2.1
BRAND=Hisense
PHONE_MODEL=M470BSA
STACK_TRACE=android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.media.action.IMAGE_CAPTURE (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
at android.app.Activity.startActivityForResult(Activity.java:3370)
at android.app.Activity.startActivityForResult(Activity.java:3331)
...
I have put some exception handling around the code to catch the exception and show an error, but I have no idea why this piece of code is failing on this device. The user confirmed that the camera is working fine.
First, there is no requirement that a device have an activity that supports ACTION_IMAGE_CAPTURE, even if the device has an actual camera.
Second, particularly on Android 4.3+ tablets, the person using the device may not have access to an ACTION_IMAGE_CAPTURE activity, even if one is installed, as the person may be running in a restricted profile.
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.
I'm getting the following exception during an ACTION_SEND intent with a data type application/pdf:
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.SEND typ=application/pdf flg=0x3080000 cmp=com.adobe.reader/.ARSendForSignature (has extras) }
This brings up a dialog to choose the desired application to receive the PDF. I believe the SecurityException is being thrown when a user chooses Adobe Reader from the list, although it appears to be opening specifically the ARSendForSignature activity.
Any ideas?
You are encountering a bug in the Adobe Reader app, or a bug in Android, depending upon your perspective.
The Adobe Reader ARSendForSignature activity supports the ACTION_SEND <intent-filter>, but they explicitly have android:exported="false", which denies anyone but them the ability to start that activity.
Either:
Adobe Reader should not have that <intent-filter>, or
Adobe Reader should not have marked it as not exported, or
The Android chooser should filter out non-exported activities
Long-term, the answer should be #3 -- I'll work on reproducing this problem and will file an issue, assuming there isn't already one. Short-term, Adobe can fix this faster than we can fix a couple hundred million devices. :-)