0

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 例外が発生しています

4

2 に答える 2

0

WRITE_EXTERNAL_STORAGE簡単にできる許可が必要です

sourceFile.renameTo(destFile);

のドキュメントはrenameTo言う

このファイルの名前を newPath に変更します。この操作は、ファイルとディレクトリの両方でサポートされています

ここで見つけることができます

于 2013-05-12T14:18:25.057 に答える