0

I'm trying to unmount and mount USB devices programmatically. I can do it in adb with these commands:

umount /mnt/usb1
mount -t vfat -o rw /dev/block/sdb /mnt/usb1

But when I try to execute these commands from my app it doesn't work. Here is the codes I use:

Process proc = Runtime.getRuntime().exec(
                    new String[] { "/system/xbin/su", "-c",
                            "umount /mnt/usb1" });
proc.waitFor();

Process pr = Runtime.getRuntime().exec(new String[] {
              "/system/xbin/su", "-c",
              "mount -t vfat -o rw /dev/block/sdb /mnt/usb1" });
pr.waitFor();

Description of exec() method says: "Executes the specified command and its arguments in a separate native process. " So I think that command works but in a different process. In the process which my app runs, nothing gets effected. So I want to execute these commands in the process that my app runs.

I can get the process ID, thanks to this question . Is there a way to use this process ID to call current process and execute shell commands?

Community
  • 1
  • 1
MilesDyson
  • 738
  • 1
  • 11
  • 33

1 Answers1

1

I think that is not possible, Because : can you execute the command to kill the process from the same process . So that will not be possible at this time,May be they will extend the Process to include limited restrictions.

Viswanath Lekshmanan
  • 9,945
  • 1
  • 40
  • 64