2012-05-04 74 views
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(); 
      } 

回答

0

我的第一個猜測是你缺乏空間。

如果echo 255 > ...的作品,這是偉大的,但使用+來連接字符串,將不添加隱含空間,讓您的代碼將目前生產echo255> sys/class...如果微博賬號= 255。換句話說,嘗試:

os.writeBytes("echo " +uin+ " > sys/class/leds/button-backlight/brightness\n"); 

HTH