I need to get the Integer input from the user ( from the EditText numerical ) to make it to a command line, But I don’t seem to get it working, if I change the cmd line to ( “echo 255 > … “) it works, but if I try to place the user input instead of the 255 it doesn’t.
Here is the code.
public class main extends Activity {
EditText value;
int uin;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
value = (EditText) findViewById(R.id.editText2);
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
{
os.writeBytes("mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system\n" +
"exit \n");
os.flush();
process.waitFor();
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
//Button OK
Button bOK = (Button) findViewById(R.id.bOK);
bOK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
uin = Integer.parseInt(value.getText().toString());
Process process = null;
try {
process = Runtime.getRuntime().exec("su");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DataOutputStream os = new
DataOutputStream(process.getOutputStream());
try {
os.writeBytes("chmod 644 sys/class/leds/button-backlight/brightness\n");
os.writeBytes("echo" +uin+ "> sys/class/leds/button-backlight/brightness\n");
os.writeBytes("chmod 444 sys/class/leds/button-backlight/brightness\n");
os.writeBytes("exit\n");
os.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
My first guess would be your lack of spaces.
If
echo 255 > ...works, that’s great, but using the+to concatenate a string together doesn’t add implied spaces, so your code will currently produceecho255> sys/class...if uin = 255. In other words, try:HTH