0
我需要從用戶(從EditText數值)獲得整數輸入,使其到命令行,但我似乎並沒有得到它的工作,如果我將cmd行更改爲(「echo 255> ...」)它可以工作,但如果我嘗試將用戶輸入而不是255,它不會。EditText用戶輸入命令行(回聲「用戶輸入在這裏」等)
這是代碼。
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();
}