
Untitled
By: a guest on
Aug 10th, 2012 | syntax:
None | size: 1.08 KB | hits: 7 | expires: Never
public class mainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button bLightOn = (Button) findViewById(R.id.button1);
bLightOn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("echo 0 > /sys/class/gpio/gpio168/value");
os.writeBytes("cat /sys/class/gpio/gpio168/value \n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (Exception e) {
return;
}
finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
// Be Happy :)
}
}
}
});