1# @ohos.deviceStatus.dragInteraction (Drag Interaction) (System API) 2 3The **dragInteraction** module provides the APIs to enable and disable listening for dragging status changes. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> - The APIs provided by this module are system APIs. 10 11## Modules to Import 12 13```js 14import { dragInteraction } from '@kit.ArkUI' 15``` 16 17## DragState 18 19Enumerates dragging states. 20 21**System API**: This is a system API. 22 23**System capability**: SystemCapability.Msdp.DeviceStatus.Drag 24 25| Name | Value | Description | 26| --------------------- | ---- | -------------- | 27| MSG_DRAG_STATE_START | 1 | Dragging starts. | 28| MSG_DRAG_STATE_STOP | 2 | Dragging is ended. | 29| MSG_DRAG_STATE_CANCEL | 3 | Dragging is canceled. | 30 31## Summary<sup>11+</sup> 32 33Defines the data summary of the dragged object. 34 35**System API**: This is a system API. 36 37**System capability**: SystemCapability.Msdp.DeviceStatus.Drag 38 39| Name | Type | Mandatory | Description | 40| ---------- | -------- | ---- | ------------------ | 41| dataType | string | Yes | Type of the dragged object. | 42| dataSize | number | Yes | Data length of the dragged object. | 43 44## dragInteraction.on('drag') 45 46on(type: 'drag', callback: Callback\<DragState>): void 47 48Enables listening for dragging status changes. 49 50**System API**: This is a system API. 51 52**System capability**: SystemCapability.Msdp.DeviceStatus.Drag 53 54**Parameters** 55 56| Name | Type | Mandatory | Description | 57| -------- | ---------------------------------- | ---- | -------------------------------- | 58| type | string | Yes | Event type. This field has a fixed value of **drag**. | 59| callback | Callback\<[DragState](#dragstate)> | Yes | Callback used to return the dragging status. | 60 61**Error codes** 62 63For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 64 65| ID | Error Message | 66| -------- | ----------------- | 67| 202 | Not system application. | 68| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. | 69 70**Example** 71 72```ts 73try { 74 dragInteraction.on('drag', (data: dragInteraction.DragState) => { 75 console.log(`Drag interaction event: ${JSON.stringify(data)}`); 76 }); 77} catch (error) { 78 console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 79} 80``` 81 82## dragInteraction.off('drag') 83 84off(type: 'drag', callback?: Callback\<DragState>): void 85 86Disables listening for dragging status changes. 87 88**System API**: This is a system API. 89 90**System capability**: SystemCapability.Msdp.DeviceStatus.Drag 91 92**Parameters** 93 94| Name | Type | Mandatory | Description | 95| -------- | ---------------------------------- | ---- | ---------------------------------------------------------------------- | 96| type | string | Yes | Event type. This field has a fixed value of **drag**. | 97| callback | Callback\<[DragState](#dragstate)> | No | Callback to be unregistered. If this parameter is not specified, all callbacks registered by the current application will be unregistered. | 98 99**Error codes** 100 101For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 102 103| ID | Error Message | 104| -------- | ----------------- | 105| 202 | Not system application. | 106| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. | 107 108**Example** 109 110```ts 111// Unregister a single callback. 112function single_callback(event: dragInteraction.DragState) { 113 console.log(`Drag interaction event: ${JSON.stringify(event)}`); 114 return false; 115} 116try { 117 dragInteraction.on('drag', single_callback); 118 dragInteraction.off("drag", single_callback); 119} catch (error) { 120 console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 121} 122``` 123 124```ts 125// Unregister all callbacks. 126function all_callback(event: dragInteraction.DragState) { 127 console.log(`Drag interaction event: ${JSON.stringify(event)}`); 128 return false; 129} 130try { 131 dragInteraction.on('drag', all_callback); 132 dragInteraction.off("drag"); 133} catch (error) { 134 console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 135} 136``` 137 138## dragInteraction.getDataSummary<sup>11+</sup> 139 140getDataSummary(): Array\<Summary> 141 142Obtains the data summary of all dragged objects. 143 144**System API**: This is a system API. 145 146**System capability**: SystemCapability.Msdp.DeviceStatus.Drag 147 148**Return value** 149 150| Type | Description | 151| ----------------------------- | ---------------------------------------------------- | 152| Array\<[Summary](#summary11)> | Data summary of all dragged objects, including their type and data length. | 153 154**Error codes** 155 156For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 157 158| ID | Error Message | 159| -------- | ----------------- | 160| 202 | Not system application. | 161 162**Example** 163 164```ts 165let summarys: Array<dragInteraction.Summary> = dragInteraction.getDataSummary(); 166console.log(`Drag interaction summarys: ${JSON.stringify(summarys)}`); 167``` 168