Last active
December 12, 2015 04:18
-
-
Save jschmid/4713411 to your computer and use it in GitHub Desktop.
Android keep screen on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.WAKE_LOCK" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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