I currently have an application that will take a picture upon button click. However the photos are being stored under the application directory in a "Pictures" folder. How do you save or copy the images to the general DCIM folder that can be viewed in the general Android Photos Gallery.
An example would be great!
Location in MainActivity.java where I specify directory
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 = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, //prefix
".jpg", //suffix
storageDir //directory
);
//Save a file: path
currentPhotoPath = image.getAbsolutePath();
return image;
}
public void addImageToGallery(final String filePath, String imageName,Context mContext,String description) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
values.put(MediaStore.MediaColumns.DATA, filePath);
//adding images to Media Gallery using MediaStore
try {
MediaStore.Images.Media.insertImage(mContext.getContentResolver(), filePath, imageName, description);
}catch (Exception e){
Log.i("Error","error in inserting image");
e.printStackTrace();
}
}
Then to call it:
addImageToGallery(filepath,imageName,this,description);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments