How to save or move image files from application to general media folder

westerie

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;
    }

unmanned15
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.

edited at
0

Comments

0 comments
Login to comment

Related

Save An Image To Application Documents Folder From UIView On IOS

PhoneGap - How to make a copy of image and save in application folder?

How can I move an image from one folder to another folder?

How to move files from folder to folder based on name and Basename

SAS automation move files from folder to folder

How to Move image file from gallery to another folder

How to move a folder of files to a variably named folder

How to save to Media folder via Mediastore in CameraX?

python - how to move only updated files from folder to folder?

How can I save Image files in in my project folder?

Move unique files from a folder with duplicates files

How to move 100 files from a folder containing thousands?

How to Save Image to Application Folder from UIImagePickerController?

how to move files from subfolder to parent folder?

How to move files from parent folder and not it's subfolders?

How to move missing files only from source to target folder

How to Move extraneous files to folder?

How to play media files from folder and subfolders or directory and subdirectories in Windows?

How to save image from URL in server folder using php or javascript?

How to move 15 files from a folder containing thousands?

How to save an image in a folder?

how to save the data from database to a folder in mvc application

Google Apps Scripts: How to save files from root to a specific folder?

How do you move files from one folder to the other?

How can I move image files to a folder?

How to get and save image to folder from listview

How to save image from url into assets folder

how to get the application folder from the docker image

How to move files on Drive folder from Google Collab?