Springe zum Inhalt

Three methods to ensure your android display stays on and bright

The most common method found in the internet for keeping the display on is the one using a WakeLock:

PowerManager.WakeLock mWakeLock;
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
 mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "HomeActivity");
mWakeLock.acquire();
// ... do your business ...
mWakeLock.release();

However, there are much simpler ways:

In your activity, call

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

or

getCurrentFocus().setKeepScreenOn(true);

And you're done.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert