Hong
Hong

Reputation: 18501

What is the robust way to open Gallery of Android in code?

I have the following currently:

Intent intent = new Intent(Intent.ACTION_VIEW, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivity(intent);

It works perfectly in most cases, but it generates the following exception at least for an Android 2.3.4 device:

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

Could anyone share a universal way to open Gallery on Android devices?

Upvotes: 2

Views: 349

Answers (1)

MarkMan
MarkMan

Reputation: 184

If you are talking about opening the picture gallery, the below can be used to select an image from the SD card:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);//only local images
startActivityForResult(intent, IMAGE_PICK_ADD);

Upvotes: 1

Related Questions