gellery Intent.ACTION_SEND_MULTIPLE インテントから複数の uri を取得しています
これらのファイルを新しい場所「/sdcard/BACKUP/」にコピーするだけです
コードは次のとおりです。
ArrayList<Uri> imageUris = null;
if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
String root = Environment.getExternalStorageDirectory().getAbsolutePath()+"/";
File createDir = new File(root+"BACKUP"+File.separator);
if(!createDir.exists()) {
createDir.mkdir();
}
for (Uri uri : imageUris){
File file = new File(uri.getPath());
File newfile = new File(root + "BACKUP" + File.separator + uri.toString() +".jpg" );
copyFile(file,newfile);
}
private void copyFile(File sourceFile, File destFile) throws IOException {
if (!sourceFile.exists()) {
return;
}
FileChannel source = null;
FileChannel destination = null;
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
if (destination != null && source != null) {
destination.transferFrom(source, 0, source.size());
}
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
}
}
java.io.Filenotfound 例外が発生しています