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