Android Keep screen on(保持屏幕唤醒)
精选
转载
方法 1: use PowerManager and WakeLock
AndroidManifest.xml权限:
<uses-permission
android:name="android.permission.WAKE_LOCK" />
程序中的代码:
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: use the window flag FLAG_KEEP_SCREEN_ON
把下面的代码加入到程序onCreate方法中:
@Override
protected void onCreate(Bundle icicle)
{
super.onCreate(icicle);
// Set keep screen on
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}