1

i want to pick an image from the gallery, but i want the gallery to only show images. I create my intent like this, but i still see videos on some devices

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

EDIT:

for kitkat devices i build the intent like this.

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
AdrianoCelentano
  • 2,461
  • 3
  • 31
  • 42

2 Answers2

0
please try this one    

if (Build.VERSION.SDK_INT < 19) 
{ 
Intent intent = new Intent(); 
intent.setType("image/jpeg"); 
intent.setAction(Intent.ACTION_GET_CONTENT); 
startActivityForResult( DialogsFragment.this, 
Intent.createChooser(intent, "Select Picture"), GALLERY_INTENT_CALLED); 
} 
else 
{ 
Intent intent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult( DialogsFragment.this, intent,GALLERY_KITKAT_INTENT_CALLED); 
}
Jatin
  • 1,650
  • 3
  • 17
  • 32
  • this is actually the same i do, without setting the mime type – AdrianoCelentano Sep 19 '14 at 09:56
  • Have to put condition version wise – Jatin Sep 19 '14 at 10:00
  • if (Build.VERSION.SDK_INT < 19) { Intent intent = new Intent(); intent.setType("image/jpeg"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult( DialogsFragment.this, Intent.createChooser(intent, "Select Picture"), GALLERY_INTENT_CALLED); } else { Intent intent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult( DialogsFragment.this, intent, GALLERY_KITKAT_INTENT_CALLED); } – Jatin Sep 19 '14 at 10:00
  • 2
    Jatin update your answer instead of pasting code in comments. – SilentKiller Sep 19 '14 at 10:01
0
Add conditions based on OS version

Try this    

if (Build.VERSION.SDK_INT < 19) {
                Intent intent = new Intent();
                intent.setType("image/jpeg");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(DialogsFragment.this,
                        Intent.createChooser(intent, "Select Picture"),
                        GALLERY_INTENT_CALLED);
            } else {
                Intent intent = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(DialogsFragment.this, intent,
                        GALLERY_KITKAT_INTENT_CALLED);
            }
Jatin
  • 1,650
  • 3
  • 17
  • 32