-1

Currently, I am using below code to fetch an image from gallery

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

But the issue is that its also showing GIF file, when open gallery, I want only image files, I have also tried this

galleryIntent.setType("image/jpeg, image/png");

But the result is same. How could I achieve this?

Rohit Singh
  • 16,950
  • 7
  • 90
  • 88
AJTEST
  • 111
  • 8

1 Answers1

0

Solution:

This solution is from my own project usage:

String[] mimeTypes = {"image/jpeg", "image/png"};
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT)
    .setType("image/*")
    .putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);

then startActivityForResult(galleryIntent, Constants.SELECT_GALLERY);

The Intent.ACTION_GET_CONTENT and image/* asks android to get anything that can open it, i.e. gallery, and the Intent.EXTRA_MIME_TYPES retruns those intent only those MIME types to be selectable.

This will help.

Ümañg ßürmån
  • 9,695
  • 4
  • 24
  • 41