页面需要保持屏幕常亮,有相关的api和示例吗?

如题:页面需要保持屏幕常亮,有相关的api和示例吗?

阅读 670
1 个回答

请参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-window-0000001820880785\#ZH-CN\_TOPIC\_0000001820880785\_\_setwindowkeepscreenon9

设置屏幕常亮,不熄屏。

获取窗口实例对象后,调用setWindowKeepScreenOn方法可设置屏幕是否常亮。

import { BusinessError } from '@ohos.base';
import window from '@ohos.window';
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));
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进