Search code examples
androidsystemmount

Mount R/W system in android application to edit Read Only files


How can I, within my application, edit a file in the /system/ directory?

Do I have to make the system R/W accessible?

I ve tried:

process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("mount -o remount,rw /system\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();

and many other ways, without success.

If anybody can help me, I'd greatly appreciated it! :)

Also, if i finally made it, will it worked with all rooted phones? Or is it different with some phones?


Solution

  • I use:

        os.writeBytes("mount -o remount rw /system/\n"); 
        //instead of a comma, I have a space. 
        //When I tried it with a comma, mine didn't work either.
    

    And that allows me to successfully mount.

    If you exit right after that, of course it will not work. You have to stay within the same process and use the linux commands to edit the file.

    I have no idea how to edit the files, but I suggest googling how to do things in linux terminal, and then putting the proper code in os.writeBytes("CODE_HERE");

    Though, as far as the mounting process is concerned, I don't know if that command will work universally. It may just fortunately work on my device.

    EDIT:
    I now use RootTools: http://code.google.com/p/roottools/downloads/list
    And here is the Wiki page:
    http://code.google.com/p/roottools/w/list

    But I now am using:

    RootTools.remount(file, mountType);
    //For example:
    RootTools.remount("/system/", "rw");
    

    I believe that is universal