public static final String SCREEN_OFF_TIMEOUT = "screen_off_timeout";
private final int SCREEN_TIMEOUT_VALUE_NONE = Integer.MAX_VALUE;//永不休眠
private DreamBackend mBackend;//屏保管理类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen_saver);
mBackend = DreamBackend.getInstance(ScreenSaverActivity.this);
}
private void setScreenSaverEnable(boolean isChecked) {
mBackend.setEnabled(isChecked);//设置开关的状态
if (isChecked) {
Settings.System.putInt(getContentResolver(), SCREEN_OFF_TIMEOUT, 1000 * 60 * 30);
} else {
Settings.System.putInt(getContentResolver(), SCREEN_OFF_TIMEOUT, SCREEN_TIMEOUT_VALUE_NONE);
}
}
作者:liaoff