Created
April 21, 2010 23:03
-
-
Save novoda/374535 to your computer and use it in GitHub Desktop.
Android: Enforcing a wakelock is sometimes necessary but should be used with caution as it will take it's toll on the battery.
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
import android.app.Activity; | |
import android.content.Context; | |
import android.os.Bundle; | |
import android.os.PowerManager; | |
public class DoNotDimScreen extends Activity { | |
private PowerManager.WakeLock wl; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); | |
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen"); | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
wl.release(); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
wl.acquire(); | |
} | |
} | |
You will need to include this permission in your manifest: | |
<uses-permission android:name="android.permission.WAKE_LOCK" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment