Camera image file path is not valid for Samsung Galaxy S5
I take a photo using photography intent and save it to disk. This function returns an image file that is passed to the Take Photo action.
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.
In Samsung Galaxy S5 (SM-G900V) running 5.0 mPhotoPath is zero.
source to share
This was the case where the error log errors were completely wrong. I was able to access the real device and see the local logs.
The paths were not null as indicated in the remote Crashlytics logs. 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 piece of code helped me resize the bitmap before I put it in 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);
source to share
because you don't have a device, it's hard to tell the exact problem, but try to change the way the image file is generated, you can do it 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);
source to share