Guest User

Untitled

a guest
Oct 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  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. });
Add Comment
Please, Sign In to add comment