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.

nidhi_adiga
  • 1,114
  • 1
  • 16
  • 27
Narrator
  • 113
  • 1
  • 3
  • 11

2 Answers2

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.

Jerry Ajay
  • 1,084
  • 11
  • 26
alex
  • 6,359
  • 1
  • 23
  • 21
  • 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!! – Gonzalo Solera Sep 21 '13 at 15:29
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();
}
Shiv
  • 4,569
  • 4
  • 25
  • 39
  • 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!! – Gonzalo Solera Sep 21 '13 at 15:25