Search code examples
androidimageandroid-cameraandroid-gallerypicasso

Cannot fetch images taken by camera from Gallery


I am trying to fetch image from the gallery using the following code:

private void initGalleryFetchImage() {
    Intent i = new Intent(
      Intent.ACTION_PICK,
    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(i, RESULT_LOAD_IMAGE);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = {MediaStore.Images.Media.DATA};

        Cursor cursor = getActivity().getContentResolver().query(selectedImage,
            filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        LOGI(TAG, "picturePath: " + picturePath);
        if (picturePath.startsWith("http")) {
            Picasso.with(getActivity()).load(picturePath).into(iv);
        } else {
            Picasso.with(getActivity()).load(new File(picturePath)).into(iv);
        }
    }
}

I can retrieve all the images except the one that were taken and stored by the camera application.

[☓] picturePath: /storage/emulated/0/DCIM/Camera/20141223_102304.jpg

[✓] picturePath: https://lh4.googleusercontent.com/...f3rf3.jpg
[✓] picturePath: /storage/emulated/0/DCIM/Facebook/IMG_13280625132331.jpeg
[✓] picturePath: /storage/emulated/0/Pictures/Instagram/IMG_20140521_232443.jpg
[✓] picturePath: /storage/emulated/0/LINEcamera/2014-04-12-19-47-52_deco.jpg
[✓] picturePath: /storage/emulated/0/foursquare/foursquare/1403867797152.jpg

Does anyone know how to solve this issue?


Solution

  • try this
    
    
    private void initGalleryFetchImage() {
        Intent i = new Intent(
          Intent.ACTION_PICK,
        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, RESULT_LOAD_IMAGE);
    }
    
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK ) {
    Uri selectedImage = data.getData();
                    String[] filePathColumn = { MediaStore.Images.Media.DATA };
    
                    try {
                        bmp = BitmapFactory.decodeStream(getContentResolver()
                                .openInputStream(selectedImage));
                    } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
    }}