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

  • 内容
  • 评论
  • 相关

介绍三种方法:

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

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

评论

1条评论
  1. Gravatar 头像

    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.

发表评论