Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2012
2,861
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Android: How to turn screen on and off programmatically?
  2. params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
  3. params.screenBrightness = 0;
  4. getWindow().setAttributes(params);
  5.  
  6. params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
  7. params.screenBrightness = -1f;
  8. getWindow().setAttributes(params);
  9.  
  10. PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "tag");
  11. wl.acquire();
  12.  
  13. getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
  14.  
  15. params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
  16. params.screenBrightness = 0;
  17. getWindow().setAttributes(params);
  18.  
  19. WindowManager.LayoutParams params = getWindow().getAttributes();
  20. params.screenBrightness = -1;
  21. getWindow().setAttributes(params);
  22.  
  23. WindowManager.LayoutParams params = getWindow().getAttributes();
  24. params.screenBrightness = 1;
  25. getWindow().setAttributes(params);
  26.  
  27. <uses-permission android:name="android.permission.WAKE_LOCK" />
  28.  
  29. private void unlockScreen() {
  30. Window window = this.getWindow();
  31. window.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
  32. window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
  33. window.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
  34. }
  35.  
  36. Calling hidden API in android to turn screen off
  37.  
  38. PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
  39. wl.acquire();
Advertisement
RAW Paste Data Copied
Advertisement