Bender
Bender

Reputation: 417

How to get only images from gallery

I want to get image from gallery and set as background in some layout. What I do:

    Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(intent, Constants.SELECT_IMAGE);

This intent shows me a gallery and allows pick not only pictures, but video too. But I need only images for set to background. Give me please correct sample.

this way doesn't help:

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

Upvotes: 2

Views: 172

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006624

Use ACTION_GET_CONTENT instead of ACTION_PICK, for a MIME type of image/*:

Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("image/*");
startActivityForResult(i, Constants.SELECT_IMAGE);

Upvotes: 4

Related Questions