0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

鸿蒙开发设备管理:ohos.runningLock Runninglock锁

jf_46214456 来源:jf_46214456 作者:jf_46214456 2024-07-03 17:37 次阅读

Runninglock锁

该模块主要提供Runninglock锁相关操作的接口,包括创建、查询、持锁、释放锁等操作。

icon-note.gif说明: 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 开发前请熟悉鸿蒙开发指导文档 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]

导入模块

import runningLock from '@ohos.runningLock';

RunningLockType

RunningLock锁的类型。

系统能力: 以下各项对应的系统能力均为SystemCapability.PowerManager.PowerManager.Core

名称默认值描述
BACKGROUND1阻止系统休眠的锁。
PROXIMITY_SCREEN_CONTROL2通过接近或者远离状态来控制亮灭屏的锁。

isRunningLockTypeSupported

isRunningLockTypeSupported(type: RunningLockType, callback: AsyncCallback): void

查询系统是否支持该类型的锁。

系统能力: SystemCapability.PowerManager.PowerManager.Core

参数

参数名类型必填说明
typeRunningLockType需要查询的锁的类型。
callbackAsyncCallback指定的callback回调方法,用于获取返回值。 callback返回值:支持返回true,不支持返回false。

示例:

runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND, (error, supported) = > {
    if (typeof error === "undefined") {
        console.info('BACKGROUND support status is ' + supported);
    } else {
        console.log('error: ' + error);
    }
})

isRunningLockTypeSupported

isRunningLockTypeSupported(type: RunningLockType): Promise

查询系统是否支持该类型的锁。

系统能力: SystemCapability.PowerManager.PowerManager.Core

参数:

参数名类型必填说明
typeRunningLockType需要查询的锁的类型。

返回值:

类型说明
PromisePromise实例,用于异步获取返回值,支持返回true,不支持返回false。

示例:

runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL)
.then(supported = > {
    console.info('PROXIMITY_SCREEN_CONTROL support status is ' + supported);
})
.catch(error = > {
    console.log('error: ' + error);
});

createRunningLock

createRunningLock(name: string, type: RunningLockType, callback: AsyncCallback): void

创建RunningLock锁。

系统能力: SystemCapability.PowerManager.PowerManager.Core

需要权限: ohos.permission.RUNNING_LOCK

参数:

参数名类型必填说明
namestring锁的名字。
typeRunningLockType要创建的锁的类型。
callbackAsyncCallback<[RunningLock]>指定的callback回调方法,用于获取返回的RunningLock锁对象。

示例:

runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND, (error, lockIns) = > {
    if (typeof error === "undefined") {
        console.log('create runningLock test error: ' + error);
    } else {
        var used = lockIns.isUsed();
        console.info('runninglock is used: ' + used);
        lockIns.lock(500);
        used = lockIns.isUsed();
        console.info('after lock runninglock is used ' + used);
    }
})

createRunningLock

createRunningLock(name: string, type: RunningLockType): Promise

创建Runninglock锁。

系统能力: SystemCapability.PowerManager.PowerManager.Core

需要权限: ohos.permission.RUNNING_LOCK

参数:

参数名类型必填说明
namestring锁的名字。
typeRunningLockType要创建的锁的类型。

返回值:

类型说明
Promise<[RunningLock]>Promise实例,用于异步获取返回的RunningLock锁对象。

示例:

runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND)
.then(runninglock = > {
    console.info('create runningLock success');
})
.catch(error = > {
    console.log('create runningLock test error: ' + error);
})

RunningLock

阻止系统休眠的锁。

lock

lock(timeout: number): void

锁定和持有RunningLock。

系统能力: SystemCapability.PowerManager.PowerManager.Core

需要权限: ohos.permission.RUNNING_LOCK

参数:

参数名类型必填说明
timeoutnumber锁定和持有RunningLock的时长,单位:毫秒。

示例:

runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND)
.then(runningLock = > {
    runningLock.lock(100)
    console.info('create runningLock success')
})
.catch(error = > {
    console.log('create runningLock test error: ' + error)
});

unlock

unlock(): void

释放Runninglock锁。

系统能力: SystemCapability.PowerManager.PowerManager.Core

需要权限: ohos.permission.RUNNING_LOCK

示例:

runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND)
.then(runningLock = > {
    runningLock.unlock()
    console.info('create and unLock runningLock success')
})
.catch(error = > {
    console.log('create runningLock test error: ' + error)
});

isUsed

isUsed(): boolean

查询当前Runninglock是持有状态还是释放状态。

系统能力: SystemCapability.PowerManager.PowerManager.Core

返回值:

类型说明
boolean当前RunningLock是持有状态返回true,释放状态返回false。HarmonyOSOpenHarmony鸿蒙文档籽料:mau123789是v直接拿

搜狗高速浏览器截图20240326151547.png

示例:

runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND)
.then(runningLock = > {
    var used = runningLock.isUsed()
    console.info('runningLock used status: ' + used)
})
.catch(error = > {
    console.log('runningLock isUsed test error: ' + error)
});

审核编辑 黄宇

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 接口
    +关注

    关注

    33

    文章

    7982

    浏览量

    149281
  • 鸿蒙
    +关注

    关注

    55

    文章

    2156

    浏览量

    42287
收藏 人收藏

    评论

    相关推荐

    设备管理系统软件有哪些

    设备管理系统软件有哪些,下面是 设备管理软件功能摘要的NLP颜色标记版,欢迎对比查看素版设备管理软件功能摘要,有想法反映留言,谢谢~~预测\color{#D2691E}预测预测性\color
    发表于 07-12 07:01

    基于.Net框架的设备管理系统的设计与实现

    设备管理系统是企业运营过程中必不可少的组成部分。本文以中国教育经济信息网管理中心设备管理系统为例,讨论了设备管理系统的设计与实现,并详细讨论了基于.Net框架的三
    发表于 08-28 09:02 28次下载

    面向预测性维护的制造工业设备管理系统

    为了解决制造业中工业设备管理混乱、维护成本高昂等问题,以工业机器人、数控车床等工业设备管理对象,开发面向预测性维护的设备管理系统。基于 S
    发表于 04-23 09:46 43次下载
    面向预测性维护的制造工业<b class='flag-5'>设备管理</b>系统

    设备管理系统建设的目标及意义

    结合企业现有设备管理系统方式和设备管理信息化规划要求,结合企业设备管理系统制度,为企业量身定做设备管理系统,借助信息化的方法助力设备管理过程
    的头像 发表于 02-23 10:30 847次阅读

    物通博联物联网设备管理平台快速实现远程设备管理与数据监控

    在现代工业生产中,设备管理和数据监控是确保生产效率和产品质量的关键环节。物联网技术的发展,为各行各业的设备管理带来了新的机遇和挑战,设备管理和数据监控变得越来越重要。传统的设备管理方式
    的头像 发表于 08-05 16:09 463次阅读
    物通博联物联网<b class='flag-5'>设备管理</b>平台快速实现远程<b class='flag-5'>设备管理</b>与数据监控

    设备管理云平台是什么?有什么功能?

    设备管理云平台:现代化企业的重要解决方案 随着科技的迅速发展和企业规模的扩大,设备数量和种类也随之增加,设备管理变得愈加复杂。传统的管理方法已经无法满足企业的需求,而
    的头像 发表于 09-20 16:39 966次阅读

    基于RFID油井设备管理手持机的开发研究

    电子发烧友网站提供《基于RFID油井设备管理手持机的开发研究.pdf》资料免费下载
    发表于 10-23 09:35 0次下载
    基于RFID油井<b class='flag-5'>设备管理</b>手持机的<b class='flag-5'>开发</b>研究

    鸿蒙开发接口定制管理:【@ohos.enterpriseDeviceManager (企业设备管理)】

    以异步方法根据给定的包名和类名激活设备管理员应用,使用Callback形式返回是否激活成功。
    的头像 发表于 06-05 09:24 263次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b>接口定制<b class='flag-5'>管理</b>:【@<b class='flag-5'>ohos</b>.enterpriseDeviceManager (企业<b class='flag-5'>设备管理</b>)】

    鸿蒙开发系统基础能力:ohos.screenLock 管理

    管理服务是OpenHarmony中系统服务,为屏应用提供注册亮屏、灭屏、开启屏幕、结束休眠、退出动画、请求解锁结果监听,并提供回调结果给屏应用。
    的头像 发表于 06-27 11:41 188次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b>系统基础能力:<b class='flag-5'>ohos</b>.screenLock <b class='flag-5'>锁</b>屏<b class='flag-5'>管理</b>

    鸿蒙开发设备管理ohos.deviceInfo 设备信息

    面向特定开发者发布的早期预览版本,不承诺API稳定性。 - Beta:面向开发者公开发布的Beta版本,不承诺API稳定性。
    的头像 发表于 07-01 16:33 188次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>设备管理</b>:<b class='flag-5'>ohos</b>.deviceInfo <b class='flag-5'>设备</b>信息

    鸿蒙开发设备管理ohos.multimodalInput.inputDevice 输入设备

    输入设备管理模块,用于监听输入设备连接、断开和变化,并查看输入设备相关信息。比如监听鼠标插拔,并获取鼠标的id、name和指针移动速度等信息。
    的头像 发表于 07-01 09:19 91次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>设备管理</b>:<b class='flag-5'>ohos</b>.multimodalInput.inputDevice 输入<b class='flag-5'>设备</b>

    鸿蒙开发设备管理ohos.multimodalInput.inputEvent 输入事件

    InputEvent模块描述了设备上报的基本事件。
    的头像 发表于 07-02 17:44 89次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>设备管理</b>:<b class='flag-5'>ohos</b>.multimodalInput.inputEvent 输入事件

    鸿蒙开发设备管理ohos.multimodalInput.keyCode 键值

    KeyCode模块提供了按键类设备的键值。
    的头像 发表于 07-01 22:14 82次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>设备管理</b>:<b class='flag-5'>ohos</b>.multimodalInput.keyCode 键值

    鸿蒙开发设备管理ohos.thermal 热管理

    该模块提供热管理相关的接口,包括热档位查询及注册回调等功能。
    的头像 发表于 07-05 09:53 59次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>设备管理</b>:<b class='flag-5'>ohos</b>.thermal 热<b class='flag-5'>管理</b>

    鸿蒙开发设备管理ohos.usb USB管理

    本模块主要提供管理USB设备的相关功能,包括查询USB设备列表、批量数据传输、控制命令传输、权限控制等。
    的头像 发表于 07-05 17:34 106次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>设备管理</b>:<b class='flag-5'>ohos</b>.usb USB<b class='flag-5'>管理</b>