import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';
let isKeepScreenOn: boolean = true;
let windowClass: window.Window = window.findWindow("test");
try {
windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err: BusinessError) => {
const errCode: number = err.code;
if (errCode) {
console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the screen to be always on.');
});
} catch (exception) {
console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(exception));
}
解决措施
设置屏幕常亮,不熄屏。
获取窗口实例对象后,调用setWindowKeepScreenOn方法可设置屏幕是否常亮。
参考链接
setWindowKeepScreenOn方法