android屏幕保持唤醒

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

转载地址未详: http://android6.blog.51cto.com/2035380/382792

你可能感兴趣的:(android)