I’ve been working away at a camera app that would simply just store pictures taken by the camera in a custom folder. I’ve run into a weird error that I haven’t been able to find a duplicate issue of. While my app takes and saves the picture in the folder as it should, the images aren’t viewable. The even weirder part about this is that the copy of the image that is stored in the Camera Shots folder (my phone’s default picture storage spot) IS viewable. I’ve tried revising my code in many different ways, but I’m still getting the same result. Below is my code. Any help would be greatly appreciated!
Thank you!
camera.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String name = Environment.getExternalStorageDirectory().toString();
File mainFolder = new File(name + "/Filename/");
mainFolder.mkdirs();
Random generator = new Random();
int random = 10000;
random = generator.nextInt(random);
String fileName = "Image-"+ random +".jpg";
File file = new File (mainFolder, fileName);
if (file.exists ()) file.delete ();
try {
FileOutputStream stream = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.JPEG, 90, stream);
stream.flush();
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
startActivityForResult(i, cameraData);
}
});
I figured it out. I was missing the URI. Below is the updated (and working) code for anyone who would run into this problem: