3

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.

bodagetta
  • 834
  • 8
  • 17
  • Add a log entry to log `mPhotoPath`, and see exactly what it contains. – Daniel Nugent May 21 '15 at 19:02
  • Oh, hmm. What about `storageDir.getAbsolutePath()` before you call `mkdirs()`? – Daniel Nugent May 21 '15 at 19:05
  • I don't have access to a Galaxy S5, just the crash reports. I'm using Crashlytics and have it log mPhotoPath later in the code where it crashes because it is null. Any suggestions on how to do remote logging? – bodagetta May 21 '15 at 19:06
  • @bodagetta could it be that the device's external storage is full? It sounds like you are seeing this in Crashlytics. I would check to see if you can reproduce it locally. – stevebot May 21 '15 at 19:21
  • I cannot reproduce it on a Nexus device, that's all I have available locally. – bodagetta May 22 '15 at 02:30
  • storage isn't full. Crashlytics says they user has >700MB free – bodagetta May 22 '15 at 03:17

2 Answers2

1

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);
Community
  • 1
  • 1
bodagetta
  • 834
  • 8
  • 17
0

because you don't have device it is hard to say exact problem but try to change the way that you create image file,you can do that like this:

File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
            (imageFileName + ".jpg"));
    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }//else if file exist you can delete it ,or change file name
    mPhotoPath = Uri.fromFile(file);
MHP
  • 2,613
  • 1
  • 16
  • 26