How to programmatically move , copy files to SD?
<p>I am making an android app which lets the user transfer some files from internal storage to external storage(SD card) using SAF.</p>
<p>This is how I call an intent to let the user choose the SD card directory.</p>
<pre><code>Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(intent, 42);
</code></pre>
<p>And this is my onActivityResult</p>
<pre><code> public  void onActivityResult(int requestCode, int resultCode, Intent data) {      
    treeUri = data.getData();
    final int takeFlags = data.getFlags()
        &amp; (Intent.FLAG_GRANT_READ_URI_PERMISSION
        | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    getActivity().getContentResolver().takePersistableUriPermission(treeUri, takeFlags);
 }
</code></pre>
<p>I am taking permission for whole SD card so that i can  move or delete any file in sd card any time .The problem is that even after taking permission i am not able to move or delete any file in SD card.</p>
<p>How should i move a file from internal Storage  to external(SD card) for android 5.0 and above.</p>
<p>EDIT:This is the code i am using to move files.</p>
<pre><code>public static void MoveFiles(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();
           src.delete();
        
    }
}
</code></pre>