Solution 1: use PowerManager and WakeLock

In AndroidManifest.xml:

<uses-permission android:name="android.permission.WAKE_LOCK" />

In your Activity:

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);    PowerManager.WakeLock mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");         // in onResume() call    mWakeLock.acquire();         ...    // in onPause() call    mWakeLock.release();

Solution 2: use the window flag FLAG_KEEP_SCREEN_ON

Put the following code in your Activity’s onCreate method:

    @Override    protected void onCreate(Bundle icicle) {        super.onCreate(icicle);        // Set keep screen on        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);    }

Reference

  • http://stackoverflow.com/questions/2131948/force-screen-on
  • http://stackoverflow.com/questions/992508/using-a-wakelock-in-a-service-android-1-5
  • http://stackoverflow.com/questions/1114270/android-screen-timeout

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)TextView中文字通过Spannab
  2. Android的Camera系统结构
  3. Android 启动过程详解(学习1)
  4. Android之阴影制作(Shadow)
  5. Google 手机操作系统 Android(安卓)开发
  6. Android 学习笔记(十三):Activity-GridView
  7. 2010.12.16(2)——— android 关于录制视
  8. mac下android studio打不开sdk manage
  9. 【android】android耗电量测试
  10. Android之查看外部依赖jar的源码_android