I’m purely GUESSING you forgot the necessary code from the question part of what you linked to.
The question has the following line at the very top:
Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
If you just copied the code from the answer, then you would have that error because the code in the answer does not contain the instantiation of imageIntent
.
Let me know if you need anything further or if I’m just totally wrong.
UPDATE (regarding image being overwritten):
You are currently using "image_001.jpg"
as the string that represents the image name.
Set a variable within your Class int imageNum = 0;
Then you need to use a while loop and increment the image number – or you can create a different name for the image based on the time – that is another way to do it.
String fileName = "image_" + String.valueOf(imageNum) + ".jpg";
File output = new File(imagesFolder, fileName);
while (output.exists()){
imageNum++;
fileName = "image_" + String.valueOf(imageNum) + ".jpg";
output = new File(imagesFolder, fileName);
}
//now save the file to the sdcard using output as the file
The above code – while not tested personally – should work.