android唤醒屏幕--保持屏幕唤醒-Reprinted

 

方法 1: use PowerManager and WakeLockAndroidManifest.xml权限:


程序中的代码:

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

你可能感兴趣的:(Android,Android,XML)