Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从多媒体资料设备中选择图片_Android - Fatal编程技术网

Android 从多媒体资料设备中选择图片

Android 从多媒体资料设备中选择图片,android,Android,如何从gallery设备获取图片并将其与参数一起发送到其他目的地 首先,我需要调用此方法: public void selectImageFromGallery() { try{ Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); st

如何从gallery设备获取图片并将其与参数一起发送到其他目的地

首先,我需要调用此方法:

public void selectImageFromGallery() {
        try{
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent,"Select an picture"), SELECT_IMAGE);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
我在StartActivityForResult方法中有这个

@Override
      protected void onActivityResult(int requestCode, int resultcode, Intent intent)
      {
          super.onActivityResult(requestCode, resultcode, intent);

          if (requestCode == 1) 
          {
              if (intent != null && resultcode == RESULT_OK) 
              {              

                    Uri selectedImage = intent.getData();

                    String[] filePathColumn = {MediaStore.Images.Media.DATA};
                    Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
                    cursor.moveToFirst();
                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                    String filePath = cursor.getString(columnIndex);
                    cursor.close();
              }
          }
      }

但不管用!当我从图库中选择一张图片时,什么也没有发生

我需要从gallery设备中选择一张图片并发送其他意图


有人有主意了,我非常感谢

请解释什么不起作用!方法此外,请记住,您的MediaStore.Images.Media.DATA hack可能不起作用,因为不要求您返回的Uri来自MediaStore.add this after cursor.close;位图bmp=BitmapFactory.decodeFilepicturePath;当我从gallery中选择图片时,什么都没有发生。ihsanbal我实现了这一行。但问题是在选择图片之前不返回StartActivityForResult。我不明白你为什么要这么做。。在这里,我从gallery中选择图像,然后将其设置到LinearLayouts的背景中,所以你也可以在imageView中设置,这取决于。即使我从相机中捕获图像,然后再次设置在布局的背景中。因此,有意识地仔细阅读代码,这将对你有很大帮助。