Guest User

Untitled

a guest
Aug 15th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. Android: Keep camera-LED on after screen turns off
  2. @Override
  3. public void onCreate() {
  4. // assume we start with screen on and save that state ;-)
  5. this.pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
  6. screenOn = this.pm.isScreenOn();
  7.  
  8. // program a timer which checks if the light needs to be re-activated
  9. this.mTimer = new Timer();
  10. this.mTimerTask = new TimerTask() {
  11. public void run() {
  12. // re-activate the LED if screen turned off
  13. if(!pm.isScreenOn() && pm.isScreenOn() != screenOn) {
  14. Log.i("SleepLEDservice", "re-activated the LED");
  15.  
  16. // really it's NOT ENOUGH to just "turn it on", i double-checked this
  17. setFlashlight(Camera.Parameters.FLASH_MODE_OFF);
  18. setFlashlight(Camera.Parameters.FLASH_MODE_TORCH);
  19. }
  20. screenOn = pm.isScreenOn();
  21. }
  22. };
  23. }
  24.  
  25. private void setFlashlight(String newMode) {
  26. try {
  27. this.frontCamPara = this.frontCam.getParameters();
  28. if(this.frontCamPara.getFlashMode() != newMode) {
  29. this.frontCamPara.setFlashMode(newMode);
  30. this.frontCam.setParameters(frontCamPara);
  31. }
  32. } catch (Exception e) {
  33. e.printStackTrace();
  34. }
  35. }
Add Comment
Please, Sign In to add comment