harmony 鸿蒙Motion Awareness Development
Motion Awareness Development
When to Use
An application can call the motion module to identify user actions, for example, whether the user is operating the device screen with the left hand or the right hand.
For details about the APIs, see Motion API Reference.
Available APIs
API | Description |
---|---|
on(type:‘operatingHandChanged’,callback:Callback<OperatingHandStatus>):void; | Subscribes to operating hand change events. This API uses a callback to return the result. |
off(type: ‘operatingHandChanged’, callback?: Callback<OperatingHandStatus>): void; | Unsubscribes from operating hand change events. |
getRecentOperatingHandStatus(): OperatingHandStatus; | Obtains the latest operating hand status. |
Constraints
The device must support the touchscreen and be compatible with specific chips.
Knuckle operations are not categorized as hand operations.
Multi-finger operations are not supported in window rotation scenarios.
The effective range does not include the area within 8 mm from the screen edge.
How to Develop
- Import the related modules.
import { motion } from '@kit.MultimodalAwarenessKit';
import { BusinessError } from '@kit.BasicServicesKit';
- Define a callback to receive operating hand change results.
callback(data:motion.OperatingHandStatus) {
console.info('callback success' + data);
}
- Subscribe to operating hand change results.
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);
}
- Unsubscribe from operating hand change events.
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);
}
- Obtain the latest operating hand status.
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
harmony 鸿蒙Device Status Awareness Development
0
赞
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦