Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 1.08 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class mainActivity extends Activity {
  2.     /** Called when the activity is first created. */
  3.     @Override
  4.     public void onCreate(Bundle savedInstanceState) {
  5.         super.onCreate(savedInstanceState);
  6.         setContentView(R.layout.main);
  7.        
  8.         Button bLightOn = (Button) findViewById(R.id.button1);
  9.         bLightOn.setOnClickListener(new View.OnClickListener() {
  10.                        
  11.                         public void onClick(View v) {
  12.                                 // TODO Auto-generated method stub
  13.                                 Process process = null;
  14.                                 DataOutputStream os = null;
  15.                                 try {
  16.                                         process = Runtime.getRuntime().exec("su");
  17.                                         os = new DataOutputStream(process.getOutputStream());
  18.                                         os.writeBytes("echo 0 > /sys/class/gpio/gpio168/value");
  19.                                         os.writeBytes("cat /sys/class/gpio/gpio168/value \n");
  20.                                         os.writeBytes("exit\n");
  21.                                         os.flush();
  22.                                         process.waitFor();
  23.                                        
  24.                                         } catch (Exception e) {
  25.                                         return;
  26.                                         }
  27.                                         finally {
  28.                                         try {
  29.                                         if (os != null) {
  30.                                         os.close();
  31.                                         }
  32.                                         process.destroy();
  33.                                         } catch (Exception e) {
  34.                                         // Be Happy :)
  35.                                         }
  36.        
  37.                         }
  38.                         }
  39.                         });