让屏幕保持一直亮

 @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
最好别用

PowerManager and the WAKE_LOCK permission

AndroidManifest.xml:

<uses-permission android:name="android.permission.WAKE_LOCK" /> 

Activity:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); mWakeLock.acquire(); // ... mWakeLock.release();
因为此种方法在周期循环的时候会出现异常

你可能感兴趣的:(android,xml)