Reputation: 1327
I am trying to save an image by taking the picture then load it into my application. But the problem I am facing is the picture always saved with different names so I failed to load it. (I check my file manager and i saw the picture I took saved with different names.)
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, RESULT_TAKE_PHOTO);
}
}
private File createImageFile() throws IOException {
// Create an image file name
String imageFileName = "puzzle";
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
I cant identify why it always save with different names.
Upvotes: 0
Views: 156
Reputation: 1006779
I cant identify why it always save with different names.
Because you told it to, by using createTempFile()
. The point behind using createTempFile()
is to create a File
with a unique filename. If you do not want a unique filename, do not use createTempFile()
.
Upvotes: 1