【发布时间】:2018-07-30 08:22:34
【问题描述】:
大家好,我正在尝试将图像从一个文件夹复制到另一个用户从图库中选择的文件夹。它也没有抛出任何错误。请检查以下代码。
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;
}}
【问题讨论】:
标签: android android-file onactivityresult filechannel