Skip to content

Instantly share code, notes, and snippets.

@kevalpatel2106
Created May 9, 2017 02:23
Show Gist options
  • Save kevalpatel2106/ec70894cfd7b6419af17bf0c882b119e to your computer and use it in GitHub Desktop.
Save kevalpatel2106/ec70894cfd7b6419af17bf0c882b119e to your computer and use it in GitHub Desktop.
//Here is the mount drive function which I called in onCreate of my activity.
private void mountDrive() throws IOException, InterruptedException {
Process mProcess = Runtime.getRuntime().exec("/system/xbin/su");
BufferedReader reader = new BufferedReader(new InputStreamReader(mProcess.getInputStream()));
DataOutputStream dos = new DataOutputStream(mProcess.getOutputStream());
dos.writeBytes("mkdir /mnt/usb\n");
dos.flush();
dos.writeBytes("mount -t vfat -o rw /dev/block/sda1 /mnt/usb\n");
dos.flush();
dos.writeBytes("exit\n");
//Read the response
String line, result = "";
while ((line = reader.readLine()) != null) {
result += line;
Log.d("CMD","RESULT:"+result);
}
reader.close();
dos.flush();
dos.close();
mProcess.waitFor();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment