介绍三种方法:
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);
总结:常亮的前提是你不按电源键哈~~~一按肯定黑屏,(*^__^*) ...
文章评论
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.