Thursday, February 24, 2011

Android Display How to stop screen from dimming by enforcing wake lock?

By Magesh Kumar   Posted at  3:55 AM   Android No comments


Enforcing a wakelock is sometimes necessary but should be used with caution as it will take it's toll on the battery. 
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" />

About the Author

Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: BT9

0 comments:

Back to top ↑
Connect with Us

What they says

© 2013 MaGeSH 2 help. WP Mythemeshop Converted by BloggerTheme9
Blogger templates. Proudly Powered by Blogger.