Skip to content

Instantly share code, notes, and snippets.

@jschmid
Last active December 12, 2015 04:18
Show Gist options
  • Save jschmid/4713411 to your computer and use it in GitHub Desktop.
Save jschmid/4713411 to your computer and use it in GitHub Desktop.
Android keep screen on
<uses-permission android:name="android.permission.WAKE_LOCK" />
public class MyActivity extends Activity {
protected PowerManager.WakeLock mWakeLock;
@Override
public void onCreate(final Bundle bundle) {
setContentView(R.layout.main);
/* This code together with the one in onDestroy()
* will make the screen be always on until this Activity gets destroyed. */
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
this.mWakeLock.acquire();
}
@Override
public void onDestroy() {
this.mWakeLock.release();
super.onDestroy();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment