Image Upload using intent

心已入冬 提交于 2019-12-04 13:20:27

I just changed the code as following:

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

    if (requestCode == PICK_IMAGE && null != data) {
        if (resultCode == getActivity().RESULT_OK) {
            selectedImage = data.getData();
            Log.i("selectedImage", "selectedImage: " + selectedImage.toString());
            String[] filePathColumn = {MediaStore.Images.Media.DATA};

            Cursor cursor = getActivity().getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor
                    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();

            Log.i("columnIndex", "columnIndex: " + columnIndex);

            String picturePath = cursor.getString(columnIndex);
            Log.i("picturePath", "picturePath: " + picturePath);
            cursor.close();

        }
    }


}

  public void selectImageFromGallery(){
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(galleryIntent, PICK_IMAGE);}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!