Stop screen from dimming by enforcing wake lock in Android

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" /> // see http://www.androidsnippets.com/stop-screen-from-dimming-by-enforcing-wake-lock
Snippet that shows how to stop screen from dimming by enforcing wake lock.

#android #screen #dimming #wakelock

#cesarnog

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.