Prashant Kadam Prashant Kadam - 14 days ago 7
Android Question

How to Copy Image File from Gallery to another folder programatically in Android

i want to pick image from Gallery in and copy it in to other Folder in SDCard.

Code to Pick Image from Gallary

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, REQUEST_CODE_CHOOSE_PICTURE_FROM_GALLARY);


i get
content://media/external/images/media/681
this URI onActivityResult.

i want to copy the image,

Form
path ="content://media/external/images/media/681


To
path = "file:///mnt/sdcard/sharedresources/
this path of sdcard in Android.

how to do this ?

Answer
OutputStream out;
            String root = Environment.getExternalStorageDirectory().getAbsolutePath()+"/";
            File createDir = new File(root+"Folder Name"+File.separator);
            if(!createDir.exists()) {
                createDir.mkdir();
            }
            File file = new File(root + "Folder Name" + File.separator +"Name of File");
            file.createNewFile();
            out = new FileOutputStream(file);                       

        out.write(data);
        out.close();

Hope it will help u

Comments