• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.mulitmodalawareness.motion (Motion Sensing)
2
3The **motion** module provides the capability of sensing user motions, including user gestures and actions.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 15. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9
10## Modules to Import
11
12```ts
13import { motion } from '@kit.MultimodalAwarenessKit';
14```
15
16## OperatingHandStatus
17
18Defines the status of the operating hand.
19
20**System capability**: SystemCapability.MultimodalAwarness.Motion
21
22| Name               | Value  | Description                  |
23| ------------------- | ---- | ---------------------- |
24| UNKNOWN_STATUS  | 0    | Unknown status.|
25| LEFT_HAND_OPERATED  | 1    | Left hand in use.|
26| RIGHT_HAND_OPERATED | 2    | Right hand in use.|
27
28
29
30
31## motion.on('operatingHandChanged')
32
33 on(type: 'operatingHandChanged', callback: Callback<OperatingHandStatus>): void;
34
35Subscribes to operating hand change events.
36
37**Required permissions**: ohos.permission.ACTIVITY_MOTION
38
39**System capability**: SystemCapability.MultimodalAwarness.Motion
40
41**Parameters**
42
43| Name  | Type                            | Mandatory| Description                                                        |
44| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
45| type     | string                           | Yes  | Event type. Event type. This parameter has a fixed value of **operatingHandChanged**.|
46| callback | Callback<[OperatingHandStatus](#operatinghandstatus)> | Yes  | Callback used to return the operating hand status.                                  |
47
48**Error codes**
49
50For details about the error codes, see [Motion Sensing Error Codes](errorcode-motion.md) and [Universal Error Codes](../errorcode-universal.md).
51
52| ID| Error Message                                                    |
53| -------- | ------------------------------------------------------------ |
54| 201      | Permission denied.                                           |
55| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
56| 801      | Capability not supported.Function can not work correctly due to limited device capabilities. |
57| 31500001 | Service exception.                                           |
58| 31500002 | Subscribe Failed.                                            |
59
60**Example**
61
62```ts
63motion.on('operatingHandChanged', (data:motion.OperatingHandStatus) => {
64    console.info('on success' + data);
65})
66```
67
68
69
70## motion.off('operatingHandChanged')
71
72off(type: 'operatingHandChanged', callback?: Callback<OperatingHandStatus>): void;
73
74Unsubscribes from operating hand change events.
75
76**Required permissions**: ohos.permission.ACTIVITY_MOTION
77
78**System capability**: SystemCapability.MultimodalAwarness.Motion
79
80**Parameters**
81
82| Name  | Type                            | Mandatory| Description                                                        |
83| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
84| type     | string                           | Yes  | Event type. Event type. This parameter has a fixed value of **operatingHandChanged**.|
85| callback | Callback<[OperatingHandStatus](#operatinghandstatus)> | No  | Callback used to return the operating hand status.                                  |
86
87**Error codes**
88
89For details about the error codes, see [Motion Sensing Error Codes](errorcode-motion.md) and [Universal Error Codes](../errorcode-universal.md).
90
91| ID| Error Message                                                    |
92| -------- | ------------------------------------------------------------ |
93| 201      | Permission denied.                                           |
94| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
95| 801      | Capability not supported.Function can not work correctly due to limited device capabilities. |
96| 31500001 | Service exception.                                           |
97| 31500003 | UnSubscribe Failed.                                          |
98
99**Example**
100
101```ts
102motion.off('operatingHandChanged', (data:motion.OperatingHandStatus) => {
103    console.info('off success' + data);
104})
105```
106
107
108
109## motion.getRecentOperatingHandStatus()
110
111getRecentOperatingHandStatus(): OperatingHandStatus;
112
113Obtains the latest operating hand status.
114
115**Required permissions**: ohos.permission.ACTIVITY_MOTION
116
117**System capability**: SystemCapability.MultimodalAwarness.Motion
118
119**Error codes**
120
121For details about the error codes, see [Motion Sensing Error Codes](errorcode-motion.md) and [Universal Error Codes](../errorcode-universal.md).
122
123| ID| Error Message                                                    |
124| -------- | ------------------------------------------------------------ |
125| 201      | Permission denied.                                           |
126| 801      | Capability not supported.Function can not work correctly due to limited device capabilities. |
127| 31500001 | Service exception.                                           |
128
129**Example**
130
131```ts
132let data:motion.OperatingHandStatus = motion.getRecentOperatingHandStatus();
133console.info('get success' + data);
134```
135