android : how to run a shell command from within code -


I am trying to execute a command from within my code, the command "echo 125" / sys / devices / Platform / Flashlight.0 / leds / flashlight / brightness "and I can run it without problems with ADB open

I am using runtime class to execute it:

< Pre> runtime.) .exec ("echo 125> /sys/devices/platform/flashlight.0/leds/flashlight/brightness");

Although I have a I get the permission error because the sys directory I do not have access. I have also tried to place the command in a string [] if the problem happened due to the empty space but it did not make much different.

Find out the solution?

The phone needs to be rooted, after that you can do something like this :

  Public static zero DoCmds (list & lt; string & gt; cmds) throws exceptions {process process = runtime .Greattime (). Exec ("su"); DataOutputStream OS = New DataOutputStream (process.getOutputStream ()); For (String TMPCMD: CMDS) {OIITTITITES (TMPCMD + "\ n"); } Os.writeBytes ("Exit \ n"); Os.flush (); Os.close (); Process.waitFor (); }  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -