How do I make my app use the default "Gallery" to pick up the path of an image?

Asked

Viewed 1,075 times

0

I’ve seen some apps who uses the default Android Gallery to grab images from a certain folder, how do I do this?

Is it possible some Android come without the Gallery app? Or the person remove?

1 answer

2

Responding to the contrary:

Is it possible some Android come without the Gallery app? Or the person remove?

Yes, it is. In custom rom it is possible to remove and in Android default, since API 14 or 15, I do not remember exactly, one can go in Settings, Apps and disable an application. Doesn’t remove from your phone, but it’s the same effect, the app is totally unavailable.

I’ve seen some apps who uses the default Android Gallery to grab images from a certain folder, how do I do this?

Launch an Intent with the ACTION_GET_CONTENT action and handle the return on onActivityResult:

static final int REQUEST_IMAGE_OPEN = 1;

public void selectImage() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.setType("image/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    // Only the system receives the ACTION_OPEN_DOCUMENT, so no need to test.
    startActivityForResult(intent, REQUEST_IMAGE_OPEN);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_OPEN && resultCode == RESULT_OK) {
        Uri fullPhotoUri = data.getData();
        // Do work with full size photo saved at fullPhotoUri
        ...
    }
}

The above code came from the Android documentation itself.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.