【问题标题】:Gallery pick only images图库仅选择图像
【发布时间】:2014-09-19 09:50:48
【问题描述】:

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

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/*");

【问题讨论】:

  • 此链接是关于将位图从文件加载到网格视图中

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


【解决方案1】:
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 这个问题有两个不同的答案?
【解决方案2】:

试试这个:

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

【讨论】:

  • 很抱歉,但我提供了两个选项。你试过第一个选项吗?
  • 我可能没看到,你可以编辑你的遮阳篷吗?
【解决方案3】:
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); 
}

【讨论】:

  • 这其实和我一样,没有设置mime类型
  • 必须明智地放置条件版本
  • if (Build.VERSION.SDK_INT
  • Jatin 更新您的答案,而不是在 cmets 中粘贴代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多