简体   繁体   中英

Access and manipulate files and directories on an external USB storage in a rooted Android device

It's clear to me now that it's very hard (currently) to copy, move, etc. files in an external usb device in Android, as there are no high level classes to do this.

I'm considering doing my app only work on rooted devices. I've read that it's possible (and much easier) to copy files to and from a usb device in a rooted android device as one can use the operating system commands for this.

However, I've found nothing about how to really do this and if it would work on all rooted devices.

What I need is to allow from the UI the user to browse the files in the device, select those he wants and allow him to copy the files to the android device (and back).

The external USB storage should be found in /storage/ . There are USB drives there from AF. As for choosing files, you might want to try AndroidFileBrowser . Here is a snippet of code that you could use to copy files:

public void copy(File src, File dst) throws IOException
{
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);

// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
}
in.close();
out.close();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM