Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Activity found to handle Intent { act=android.intent.action.PICK dat=content://media/external/images/media }

In my app I let users pick a photo from their gallery. I use an intent like this:

Intent pickPictureIntent = new Intent(Intent.ACTION_PICK,
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

And before I start this intent I check if there is any app that can handle it:

if (pickPictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
    startActivityForResult(pickPictureIntent, SELECT_PICTURE_FROM_GALLERY_REQUEST_CODE);
}

But two of my users get this exception when they try to pick a photo from their gallery:

Exception android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK dat=content://media/external/images/media }

As far I know this happens when there is no activity to handle the intent but as you see I check the possibility of having no activity to handle the intent in my code.

like image 323
Mostafa Avatar asked Aug 16 '17 07:08

Mostafa


People also ask

What is intent in Android?

You can think of intent as a way (or intention) to open another activity. You can use the above example to start an activity, and the activity you are starting is “intent”. After we have inputted the above code, what we will do is to call the method startActivity ( ) by passing it to a container called intent.

Why do I see no activity found to handle intent?

You see no activity found to handle intent when you attempt to launch an intent either to open a link or to access an app component. It’s an error message that is caused because the device is not an official android, Google Play is not supported, or it’s a rooted device.

How to fix the error when intent object fails to work?

To fix this error, you will need to identify and verify the error. There is a way to verify the error, the activity will receive the intent, call [resolveActivity ( ) ] on your intent object.

Is it safe to call startactivity( )?

But if the result is not null, there is at least one app that can handle the intent therefore, it is safe to call startActivity ( ). We will be considering practical examples where no activity found to handle intent error is caused by passing the wrong URL.


1 Answers

Try this:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);

This brings up the Documents app. To allow the user to also use any gallery apps they might have installed:

Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
getIntent.setType("image/*");


Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");

Intent chooserIntent = Intent.createChooser(getIntent, "Select Image");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});

startActivityForResult(chooserIntent, PICK_IMAGE);
like image 123
Jay Patel Avatar answered Oct 19 '22 15:10

Jay Patel