脚本引擎 API

屏幕信息 API

runtime.screen.* 获取屏幕状态、尺寸、设备信息,支持截屏和唤醒。

当前:屏幕信息 API
脚本引擎 API

屏幕信息 API

runtime.screen.* 获取屏幕状态、尺寸、设备信息,支持截屏和唤醒。

概述

获取设备屏幕状态和尺寸信息,支持截屏保存和唤醒屏幕。截屏需要媒体投影权限,唤醒需要 WAKE_LOCK 权限。

方法列表

  • runtime.screen.isOn(): boolean — 屏幕是否亮屏。
  • runtime.screen.isLocked(): boolean — 屏幕是否锁定(需要解锁)。
  • runtime.screen.width(): number — 屏幕宽度(像素)。
  • runtime.screen.height(): number — 屏幕高度(像素)。
  • runtime.screen.androidVersion(): number — Android SDK 版本,如 33 (Android 13)。
  • runtime.screen.deviceModel(): string — 设备型号,如 'Xiaomi M2012K11AC'。
  • runtime.screen.capture(path): void — 截屏并保存 PNG 到指定路径(路径不为空)。
  • runtime.screen.wakeUp(durationMs): void — 唤醒屏幕并保持亮屏指定毫秒数。

调用示例

// 屏幕状态检查
if (!runtime.screen.isOn()) {
    runtime.process.log("屏幕已关闭,正在唤醒…");
    runtime.screen.wakeUp(5000);
    runtime.touch.sleep(1000);
}
if (runtime.screen.isLocked()) {
    runtime.process.warn("屏幕已锁定");
}
// 截屏保存
var path = "/sdcard/screenshot_" + Date.now() + ".png";
runtime.screen.capture(path);
runtime.process.log("截屏已保存到: " + path);
// 获取设备信息
runtime.process.log("设备: " + runtime.screen.deviceModel());
runtime.process.log("分辨率: " + runtime.screen.width() + "x" + runtime.screen.height());
runtime.process.log("Android API: " + runtime.screen.androidVersion());