title: how to copy file from Uri to a specific folder in external data storage
body: <p>I am trying to create a file organizer app but when created an activity to receive shared audio,video, or image it works fine but the problem that I want to copy that file from Uri to a specific folder in external data storage. I have tried a lot of code and read all the related questions, but no one solve my problem.</p>
  
  <p><em>this is what I tried:</em></p>
  
  <p>the permissions are</p>
  
  <pre><code>    &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  </code></pre>
  
  <blockquote>
    <p>the activity declaration at manifest:</p>
  </blockquote>
  
  <pre><code>&lt;activity
          android:name="nahamsoft.com.Home"
          android:label="@string/title_activity_home"
          android:theme="@style/AppTheme.NoActionBar"&gt;
  
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.SEND"/&gt;
              &lt;action android:name="android.intent.action.SEND_MULTIPLE"/&gt;
              &lt;category android:name="android.intent.category.DEFAULT"/&gt;
              &lt;data android:mimeType="application/vnd.google.panorama360+jpg"/&gt;
              &lt;data android:mimeType="image/*"/&gt;
              &lt;data android:mimeType="video/*"/&gt;
              &lt;data android:mimeType="audio/*"/&gt;
          &lt;/intent-filter&gt;
  
  
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.SEND"/&gt;
              &lt;category android:name="android.intent.category.DEFAULT"/&gt;
              &lt;data android:mimeType="text/plain"/&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  </code></pre>
  
  <blockquote>
    <p>the Java code to receive file is:</p>
  </blockquote>
  
  <pre><code>if(Intent.ACTION_SEND.equals(action)&amp;&amp; type!=null){
          fab.show();
          Toast.makeText(this,"send action",Toast.LENGTH_LONG).show();
          if("text/plain".equals(type)){
              handleSentText(intent);
          }else if(type.startsWith("image/")){
              try {
                  handleSentImage(intent);
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }else if(type.startsWith("video/")){
              handleSentVideo(intent);
          }else if(type.startsWith("audio/")){
              handleSentAudio(intent);
          }
      }
      else{
          Toast.makeText(this,"No data were come...",Toast.LENGTH_LONG).show();
      }
  </code></pre>
  
  <blockquote>
    <p>the methods to copy the file are:</p>
  </blockquote>
  
  <pre><code>private void handleSentAudio(Intent intent) {
  
      Uri audio=(Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM);
      Toast.makeText(this,"audio were handled",Toast.LENGTH_LONG).show();
  
  }
  
  private void handleSentVideo(Intent intent) {
  
          Toast.makeText(this,"Video were handled",Toast.LENGTH_LONG).show();
  }
  
  private void handleSentImage(Intent intent) throws IOException {
      Uri imageUri=(Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM);
  
  
      /*try {
          MoveFile(imageUri.getPath(),"/sdcard/Alarms/");
      } catch (IOException e) {
          e.printStackTrace();
      }*/
      if(imageUri!=null){
          Toast.makeText(this,"from:"+imageUri.getPath()+"\n to :"+
                  Environment.getExternalStorageDirectory().getAbsolutePath()+"/Download/",Toast.LENGTH_LONG).show();
  
          File src=new File(imageUri.toString());
          File des=new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Download/");
          copyFile(src,des);
  
      }else{
          Toast.makeText(this,"Image was not handled",Toast.LENGTH_LONG).show();
      }
  }
  
  private void handleSentText(Intent intent) {
      String sharedText=intent.getStringExtra(Intent.EXTRA_TEXT);
  
      Toast.makeText(this,"Text is come...",Toast.LENGTH_LONG).show();
  
  }
  </code></pre>
  
  <blockquote>
    <p>copy file method</p>
  </blockquote>
  
  <pre><code>public static void copyFile(File src, File dst) throws IOException
  {
  FileChannel inChannel = new FileInputStream(src).getChannel();
  FileChannel outChannel = new FileOutputStream(dst).getChannel();
  try
  {
      inChannel.transferTo(0, inChannel.size(), outChannel);
  }
  finally
  {
      if (inChannel != null)
          inChannel.close();
      if (outChannel != null)
          outChannel.close();
  }
  }
  </code></pre>
  
  <p><em>what I want is <strong>to move the handled file to specific folder which called myFolder</strong>.</em></p>