魅力程序猿

  • 首页
  • Java
  • Android
  • APP
    • 扑克计分器
    • Video Wallpaper
  • 联系我
  • 关于我
  • 资助
道子
向阳而生
  1. 首页
  2. Android
  3. 正文

Keep the screen awake throughout my activity (Android 屏幕常量)

2016年7月7日 5013点热度 0人点赞 1条评论

介绍三种方法:

1、通过PowerManager.WakeLock实现:

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

step2:

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();

2、直接通过getWindow().addFlags实现

// in onResume() call

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

// in onPause() call 

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

3、用View组件的keepScreenOn实现

step 1: 组件设置 android:keepScreenOn="true"

step 2:close: setKeepScreenOn(false); open:setKeepScreenOn(true);

总结:常亮的前提是你不按电源键哈~~~一按肯定黑屏,(*^__^*) ...

标签: Android Android 屏幕常量 屏幕常量
最后更新:2016年7月7日

daozi

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

  • Pink

    does this mean? I sure hope that Klaymans case is not over. ANyone with knowledge of what this means, please let me kntwoquo&;Dismissed with prejudice is never a good sign. He can't amend his complaint. He can appeal it. Doubtful that he'll win.

    2016年12月19日
    回复
  • razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
    回复 Pink 取消回复
    搜索
    联系方式

    QQ群:179730949
    QQ群:114559024
    欢迎您加入Android大家庭
    本人QQ:136049925

    赐我一丝安慰
    给我一点鼓励

    COPYRIGHT © 2023 魅力程序猿. ALL RIGHTS RESERVED.

    Theme Kratos Made By Seaton Jiang

    豫ICP备15000477号