openharmony 鸿蒙 js-apis-devicestatus-draginteraction-sys

2025-06-12 浏览 (1)

@ohos.deviceStatus.dragInteraction (Drag Interaction) (System API)

The dragInteraction module provides the APIs to enable and disable listening for dragging status changes.

NOTE

  • 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.

  • The APIs provided by this module are system APIs.

Modules to Import

import { dragInteraction } from '@kit.ArkUI';

DragState

Enumerates dragging states.

System API: This is a system API.

System capability: SystemCapability.Msdp.DeviceStatus.Drag

NameValueDescription
MSG_DRAG_STATE_START1Dragging starts.
MSG_DRAG_STATE_STOP2Dragging is ended.
MSG_DRAG_STATE_CANCEL3Dragging is canceled.

Summary11+

Defines the data summary of the dragged object.

System API: This is a system API.

System capability: SystemCapability.Msdp.DeviceStatus.Drag

NameTypeMandatoryDescription
dataTypestringYesType of the dragged object.
dataSizenumberYesData length of the dragged object.

dragInteraction.on('drag')

on(type: 'drag', callback: Callback<DragState>): void

Enables listening for dragging status changes.

System API: This is a system API.

System capability: SystemCapability.Msdp.DeviceStatus.Drag

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. This field has a fixed value of drag.
callbackCallback<DragState>YesCallback used to return the dragging status.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202Not system application.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed.

Example

try {
  dragInteraction.on('drag', (data: dragInteraction.DragState) => {
    console.log(`Drag interaction event: ${JSON.stringify(data)}`);
  });
} catch (error) {
  console.error(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

dragInteraction.off('drag')

off(type: 'drag', callback?: Callback<DragState>): void

Disables listening for dragging status changes.

System API: This is a system API.

System capability: SystemCapability.Msdp.DeviceStatus.Drag

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. This field has a fixed value of drag.
callbackCallback<DragState>NoCallback to be unregistered. If this parameter is not specified, all callbacks registered by the current application will be unregistered.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202Not system application.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed.

Example

// Unregister a single callback.
function single_callback(event: dragInteraction.DragState) {
  console.log(`Drag interaction event: ${JSON.stringify(event)}`);
  return false;
}
try {
  dragInteraction.on('drag', single_callback);
  dragInteraction.off("drag", single_callback);
} catch (error) {
  console.error(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// Unregister all callbacks.
function all_callback(event: dragInteraction.DragState) {
  console.log(`Drag interaction event: ${JSON.stringify(event)}`);
  return false;
}
try {
  dragInteraction.on('drag', all_callback);
  dragInteraction.off("drag");
} catch (error) {
  console.error(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

dragInteraction.getDataSummary11+

getDataSummary(): Array<Summary>

Obtains the data summary of all dragged objects.

System API: This is a system API.

System capability: SystemCapability.Msdp.DeviceStatus.Drag

Return value

TypeDescription
Array<Summary>Data summary of all dragged objects, including their type and data length.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202Not system application.

Example

let summarys: Array<dragInteraction.Summary> = dragInteraction.getDataSummary();
console.log(`Drag interaction summarys: ${JSON.stringify(summarys)}`);

dragInteraction.setDragSwitchState18+

setDragSwitchState(enabled: boolean): void

Sets the global drag-and-drop switch.

System API: This is a system API.

System capability: SystemCapability.Msdp.DeviceStatus.Drag

Parameters

NameTypeMandatoryDescription
enabledbooleanYesState of the drag-and-drop switch.
false: disabled; true: enabled.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202Not system application.

Example

dragInteraction.setDragSwitchState(false);

dragInteraction.setAppDragSwitchState18+

setAppDragSwitchState(enabled: boolean, bundleName: string): void

Sets the drag-and-drop switch for a specific application.

System API: This is a system API.

System capability: SystemCapability.Msdp.DeviceStatus.Drag

Parameters

NameTypeMandatoryDescription
enabledbooleanYesState of the drag-and-drop switch.
false: disabled; true: enabled.
bundleNamestringYesBundle name of the target application.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202Not system application.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed.

Example

dragInteraction.setAppDragSwitchState(true, "com.app.bundleName");

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkUI

harmony 鸿蒙ARKUI_TextPickerCascadeRangeContent

harmony 鸿蒙ARKUI_TextPickerRangeContent

harmony 鸿蒙ArkUI_AnimateCompleteCallback

harmony 鸿蒙ArkUI_AttributeItem

harmony 鸿蒙ArkUI_ColorStop

harmony 鸿蒙ArkUI_ContextCallback

harmony 鸿蒙ArkUI_EventModule

harmony 鸿蒙ArkUI_ExpectedFrameRateRange

harmony 鸿蒙ArkUI_IntOffset

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/g5jYpI