0

Firstly I'm new to Android.

How to execute the following shell command

echo "1" > /sys/devices/enable

in an android app.

I referred many link's but I didn't get the solution.

Is there any permission that I should mention in the manifest file to execute the shell commands in the app???.

Thanks in advance.

2 Answers 2

2
     try{
            Process process;            
            process = Runtime.getRuntime().exec("echo "1" > /sys/devices/enable");
            BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
    }
    catch (InterruptedException e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
}
Sign up to request clarification or add additional context in comments.

1 Comment

Hi @Shiv, I´m trying to use the command "ffmpeg -i input.mp4 -s 480x320 output.mp4", how should I write it using your code?? Thanks!!
2

Why not write in Java?

try{
    FileWriter fw = new FileWriter(new File("/sys/devices/enable"));
    fw.write('1');
    fw.close();
}catch(IOExceprion e){}

If you really want to invoke a shell, try this:

Runtime rt = Runtime.getRuntime();
Process p = rt.exec(new String[]{"/system/bin/sh", "-c", "echo \"1\" > /sys/devices/enable");

Make sure your device is rooted first before trying any of the above mentioned approaches.

1 Comment

Hi @alex, I´m trying to use the command "ffmpeg -i input.mp4 -s 480x320 output.mp4", how should I write it using your code?? Thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.