图库仅挑选图像

时间:2014-09-19 09:50:49

标签: android android-intent android-image android-gallery

我想从图库中选择一张图片,但我希望图库只显示图片。我创建了这样的意图,但我仍然在某些设备上看到视频

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

编辑:

对于kitkat设备,我建立了这样的意图。

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");

3 个答案:

答案 0 :(得分: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); 
}

答案 1 :(得分:0)

试试这个:

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

答案 2 :(得分: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);
            }