Hi Everyone I am trying to copy an image from one folder to another which user selects from the gallery. It's not throwing any error as well. Please check the below code.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String fileName = "";
if (resultCode == RESULT_OK) {
if (requestCode == GALLERY) {
try {
Uri selectedImageUri = data.getData();
String path = getPathFromURI(selectedImageUri);
switch (cameraNo) {
case 1:
Bitmap bitmap1 = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
imageBtn1.setImageBitmap(bitmap1);
reduceImageSize(path);
fileName = path.substring(path.lastIndexOf("/")+1);
try {
File sd = Environment.getExternalStorageDirectory();
if (sd.canWrite()) {
String destinationImagePath= "/MyImages/file.jpg";
File source= new File(path);
File destination= new File(sd, destinationImagePath);
if (source.exists()) {
FileChannel src = new FileInputStream(source).getChannel();
FileChannel dst = new FileOutputStream(destination).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Exception e) {
}
imageArrayList.add(path);
imageNameList.add(fileName);
break;
}}