FANDOM




PermissionsEdit

You will need these permissions

<uses-permission android:name="android.permission.WAKE_LOCK" />


Turning the Screen OffEdit

Apparently they are unreliable, but they have some explanatory value about how the PowerManager is interacting with the display and screen.

PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
// Choice 1

manager.goToSleep(int amountOfTime);

// Choice 2

PowerManager.WakeLock wl = manager.newWakeLock(
      PowerManager.PARTIAL_WAKE_LOCK,
      "Your Tag"
    );

wl.acquire();
wl.release();
// Choice 3
WindowManager.LayoutParams params = getWindow().getAttributes();

params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;

params.screenBrightness = 0;

getWindow().setAttributes(params);



ReferencesEdit

http://stackoverflow.com/a/6757206/329931