android调用linux命令关灯
本帖最后由 蓝天-彭 于 2015-3-16 16:20 编辑部分代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bledoff = (Button)findViewById(R.id.led_off);
//Button bledon = (Button)findViewById(R.id.bledon);
bledoff.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO 自动生成的方法存根
Process localProcess = null;
try {
localProcess = Runtime.getRuntime().exec("su");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OutputStream localOutputStream = localProcess.getOutputStream();
DataOutputStream localDataOutputStream = new DataOutputStream(localOutputStream);
try {
localDataOutputStream.writeBytes("echo 0 > /sys/class/leds/blue:ph20:led1/brightness\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//关闭LED
}
});
楼主你的apk安装了运行无效果。
页:
[1]