获取用户动作开发指导
场景介绍
当应用需要获取用户动作时,可以调用motion模块,例如判断用户当前是用左手还是右手操作设备屏幕。
详细的接口介绍请参考Motion接口。
接口说明
| 接口名 | 描述 |
|---|---|
| on(type:'operatingHandChanged',callback:Callback<OperatingHandStatus>):void; | 订阅操作手感知,操作手结果通过callback返回。 |
| off(type: 'operatingHandChanged', callback?: Callback<OperatingHandStatus>): void; | 取消订阅操作手感知。 |
| getRecentOperatingHandStatus(): OperatingHandStatus; | 获取最新的操作手状态。 |
约束与限制
-
设备需支持触控屏并兼容特定芯片。
-
指关节操作不属于使用手操作场景。
-
窗口旋转场景,多指同时操作场景不支持。
-
能力有效范围:不包含距离屏幕边缘8mm内区域。
开发步骤
-
导入模块。
import { motion } from '@kit.MultimodalAwarenessKit'; import { BusinessError } from '@kit.BasicServicesKit'; -
定义回调函数接收操作手结果
callback(data:motion.OperatingHandStatus) { console.info('callback success' + data); } -
订阅操作手感知
try { motion.on('operatingHandChanged', this.callback); console.info("on succeeded"); } catch (err) { let error = err as BusinessError; console.error("Failed on and err code is " + error.code); } -
取消订阅操作手感知
try { motion.off('operatingHandChanged'); console.info("off succeeded"); } catch (err) { let error = err as BusinessError; console.error("Failed off and err code is " + error.code); } -
获取最新操作手状态
try { let data:motion.OperatingHandStatus = motion.getRecentOperatingHandStatus(); console.info('get success' + data); } catch (err) { let error = err as BusinessError; console.error("Failed get and err code is " + error.code); }
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Multimodal Awareness Kit(多模态融合感知服务)