Monday, June 11, 2012

Android: Run linux command example

Runtime.getRuntime().exec()

For example, change chmod of a file:

             Process process = null;
             try {
                    process = Runtime.getRuntime().exec("su -c chmod 0777 file");
                    process.waitFor();
             } catch (Exception e) {
                    return false;
             }
             finally {
                    try {
                           process.destroy();
                    } catch (Exception e) {
                    }
             }
            return true;

No comments:

Post a Comment