Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path for Camera Image File is null on Samsung Galaxy S5

Tags:

android

I'm taking a photo using the take photo intent and saving it to disk. This function returns the image file that is passed to the Take Photo Intent.

Later I read the image file using this path.

private File createImageFile() throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = Environment.getExternalStorageDirectory();

        storageDir.mkdirs();
        File image = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
        );

        mPhotoPath = image.getAbsolutePath();
        return image;
    }

This code works fine on my Nexus 4 device, mPhotoPath contains a valid path.

On the Samsung Galaxy S5 (SM-G900V) running 5.0 mPhotoPath is null.

like image 583
bodagetta Avatar asked Nov 19 '25 13:11

bodagetta


1 Answers

This was an instance of the remote error logs being completely incorrect. I was able to get access to an actual device and look at the logs locally.

The paths were not null as the Crashlytics remote logs indicated. The error was trying to load a bitmap that was too large.

The debugger error was

Bitmap too large to be uploaded into a texture (2988x5312, max=4096x4096)

This code snippet helped me in resizing the bitmap before I put it into the ImageView

ImageView iv  = (ImageView)waypointListView.findViewById(R.id.waypoint_picker_photo);
Bitmap d = new BitmapDrawable(ctx.getResources() , w.photo.getAbsolutePath()).getBitmap();
int nh = (int) ( d.getHeight() * (512.0 / d.getWidth()) );
Bitmap scaled = Bitmap.createScaledBitmap(d, 512, nh, true);
iv.setImageBitmap(scaled);
like image 158
bodagetta Avatar answered Nov 21 '25 02:11

bodagetta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!