Android的获得仅图库图片 [英] Android get only image from gallery

查看:150
本文介绍了Android的获得仅图库图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让使用内置的画廊图像。它工作正常,在模拟器中它仅打开图片库,但真实设备,它给我多选其中之一就是文件管理器这使我选择任何类型的文件,甚至APK当然文件后,该应用程序崩溃
我有这个code

I’m trying to get an image using the built in gallery. It works fine in the emulator and It opens only gallery but on real device it give me multiple chooses one of them is file manager which enable me to choose any type of files even apk files of course the app crash after that I have this code

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main); 
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);


    if (resultCode == RESULT_OK) {  


    switch(requestCode){    

         case SELECT_PICTURE:
              Uri selectedImageUri = data.getData();


          break;
        }  
      }  

}

推荐答案

尝试使用

.... 
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType("image/*");
    startActivityForResult(intent, SELECT_PICTURE);
....

这篇关于Android的获得仅图库图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆