利用光传感器去判断手机与障碍物的距离,并依据与障碍物的距离发起亮灭屏的流程。
{
"name": "ohos.permission.RUNNING_LOCK"
} runningLock.create('running_lock_test', runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) .then((lock: runningLock.RunningLock) => { this.runLock = lock; this.runLock.hold(-1); }) .catch((err: Error) => { console.error(`create running lock failed, err: ${err}`); });
import { runningLock } from '@kit.BasicServicesKit'; @Entry @Component struct RunningLockDemo { message: string = '接近光锁'; private runLock: runningLock.RunningLock | null = null; build() { Column() { Text(this.message) .maxLines(10) .fontSize(50) .fontWeight(FontWeight.Bold) .alignRules({ center: { anchor: '__container__', align: VerticalAlign.Center }, middle: { anchor: '__container__', align: HorizontalAlign.Center } }); Button('启用RunningLock').onClick(() => { this.runningLock(); }); } .height('100%') .width('100%'); } runningLock() { runningLock.create('running_lock_test', runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) .then((lock: runningLock.RunningLock) => { this.runLock = lock; this.runLock.hold(-1); }) .catch((err: Error) => { console.error(`create running lock failed, err: ${err}`); }); } }