提交 95d2e4b5 编写于 作者: L LiAn 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/docs into master

Signed-off-by: NLiAn <lian15@huawei.com>
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
- [EnterpriseAdminExtensionAbility](enterprise-extensionAbility.md) - [EnterpriseAdminExtensionAbility](enterprise-extensionAbility.md)
- [InputMethodExtensionAbility](inputmethodextentionability.md) - [InputMethodExtensionAbility](inputmethodextentionability.md)
- [WindowExtensionAbility (for System Applications Only)](windowextensionability.md) - [WindowExtensionAbility (for System Applications Only)](windowextensionability.md)
- [DriverExtensionAbility](driverextensionability.md)
- Service Widget Development in Stage Model - Service Widget Development in Stage Model
- [Service Widget Overview](service-widget-overview.md) - [Service Widget Overview](service-widget-overview.md)
- Developing an ArkTS Widget - Developing an ArkTS Widget
...@@ -43,6 +44,7 @@ ...@@ -43,6 +44,7 @@
- Widget Data Interaction - Widget Data Interaction
- [Widget Data Interaction Overview](arkts-ui-widget-interaction-overview.md) - [Widget Data Interaction Overview](arkts-ui-widget-interaction-overview.md)
- [Configuring a Widget to Update Periodically](arkts-ui-widget-update-by-time.md) - [Configuring a Widget to Update Periodically](arkts-ui-widget-update-by-time.md)
- [Updating Widget Content Through a Proxy](arkts-ui-widget-update-by-proxy.md)
- [Updating Local and Online Images in the Widget](arkts-ui-widget-image-update.md) - [Updating Local and Online Images in the Widget](arkts-ui-widget-image-update.md)
- [Updating Widget Content by State](arkts-ui-widget-update-by-status.md) - [Updating Widget Content by State](arkts-ui-widget-update-by-status.md)
- [Updating Widget Content by Widget Host (for System Applications Only)](arkts-ui-widget-content-update.md) - [Updating Widget Content by Widget Host (for System Applications Only)](arkts-ui-widget-content-update.md)
...@@ -62,7 +64,6 @@ ...@@ -62,7 +64,6 @@
- [Cross-Device Migration (for System Applications Only)](hop-cross-device-migration.md) - [Cross-Device Migration (for System Applications Only)](hop-cross-device-migration.md)
- [Multi-device Collaboration (for System Applications Only)](hop-multi-device-collaboration.md) - [Multi-device Collaboration (for System Applications Only)](hop-multi-device-collaboration.md)
- [Subscribing to System Environment Variable Changes](subscribe-system-environment-variable-changes.md) - [Subscribing to System Environment Variable Changes](subscribe-system-environment-variable-changes.md)
- [Setting Atomic Services to Support Sharing](atomic-services-support-sharing.md)
- Process Model - Process Model
- [Process Model Overview](process-model-stage.md) - [Process Model Overview](process-model-stage.md)
- Common Events - Common Events
......
# Setting Atomic Services to Support Sharing
## How to Develop
1. An application calls [UIAbility.onShare()](../reference/apis/js-apis-app-ability-uiAbility.md#onshare), a lifecycle callback provided by the UIAbility component, to set the data to share. In this lifecycle callback, **ohos.extra.param.key.contentTitle** indicates the title of the content to share in the sharing box, **ohos.extra.param.key.shareAbstract** provides an abstract description of the content, and **ohos.extra.param.key.shareUrl** indicates the online address of the service. You need to set these three items as objects, with the key set to **title**, **abstract**, and **url**, respectively.
```ts
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
class MyUIAbility extends UIAbility {
onShare(wantParams) {
console.log('onShare');
wantParams['ohos.extra.param.key.contentTitle'] = {title: "OA"};
wantParams['ohos.extra.param.key.shareAbstract'] = {abstract: "communication for company employee"};
wantParams['ohos.extra.param.key.shareUrl'] = {url: "oa.example.com"};
}
}
```
2. A system dialog box calls [abilityManager.acquireShareData()](../reference/apis/js-apis-app-ability-abilityManager.md#acquiresharedata) to obtain data shared through atomic service sharing. Specifically, the system finds the UIAbility based on the mission ID and calls the **OnShare()** lifecycle of the UIAbility to obtain the shared data.
```ts
import abilityManager from '@ohos.app.ability.abilityManager';
try {
abilityManager.acquireShareData(1, (err, wantParam) => {
if (err) {
console.error(`acquireShareData fail, err: ${JSON.stringify(err)}`);
} else {
console.log(`acquireShareData success, data: ${JSON.stringify(wantParam)}`);
}
});
} catch (paramError) {
console.error(`error.code: ${JSON.stringify(paramError.code)}, error.message: ${JSON.stringify(paramError.message)}`);
}
```
# Native APIs # Native APIs
- [Using Native APIs in Application Projects](napi-guidelines.md) - [Using Native APIs in Application Projects](napi-guidelines.md)
- [Drawing Development](drawing-guidelines.md) - Graphics
- [Raw File Development](rawfile-guidelines.md) - [Drawing Development](drawing-guidelines.md)
- [Native Window Development](native-window-guidelines.md) - [NativeBuffer Development](native-buffer-guidelines.md)
- [Using MindSpore Lite for Model Inference](mindspore-lite-guidelines.md) - [NativeImage Development](native-image-guidelines.md)
- [Using MindSpore Lite for Offline Model Conversion and Inference](mindspore-lite-offline-model-guidelines.md) - [NativeVsync Development](native-vsync-guidelines.md)
- [Connecting the Neural Network Runtime to an AI Inference Framework](neural-network-runtime-guidelines.md) - [NativeWindow Development](native-window-guidelines.md)
- [Purgeable Memory Development](purgeable-memory-guidelines.md) - [Vulkan Development](vulkan-guidelines.md)
- [USB DDK Development](usb-ddk-guidelines.md) - Resource Management
\ No newline at end of file - [Raw File Development](rawfile-guidelines.md)
- AI
- [Using MindSpore Lite for Model Inference](mindspore-lite-guidelines.md)
- [Using MindSpore Lite for Offline Model Conversion and Inference](mindspore-lite-offline-model-guidelines.md)
- [Connecting the Neural Network Runtime to an AI Inference Framework](neural-network-runtime-guidelines.md)
- Memory Management
- [Purgeable Memory Development](purgeable-memory-guidelines.md)
- Device Management
- [USB DDK Development](usb-ddk-guidelines.md)
...@@ -1674,7 +1674,7 @@ between the GUI components. ...@@ -1674,7 +1674,7 @@ between the GUI components.
The following example provides a complete ArkUI-based application as an The following example provides a complete ArkUI-based application as an
illustration of GUI programming capabilities. For more details about ArkUI illustration of GUI programming capabilities. For more details about ArkUI
features, please refer to the ArkUI features, please refer to the ArkUI
[tutorial](../arkts-get-started.md). [tutorial](arkts-get-started.md).
```typescript ```typescript
// ViewModel classes --------------------------- // ViewModel classes ---------------------------
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
- [@ohos.app.ability.AbilityConstant (AbilityConstant)](js-apis-app-ability-abilityConstant.md) - [@ohos.app.ability.AbilityConstant (AbilityConstant)](js-apis-app-ability-abilityConstant.md)
- [@ohos.app.ability.abilityLifecycleCallback (AbilityLifecycleCallback)](js-apis-app-ability-abilityLifecycleCallback.md) - [@ohos.app.ability.abilityLifecycleCallback (AbilityLifecycleCallback)](js-apis-app-ability-abilityLifecycleCallback.md)
- [@ohos.app.ability.AbilityStage (AbilityStage)](js-apis-app-ability-abilityStage.md) - [@ohos.app.ability.AbilityStage (AbilityStage)](js-apis-app-ability-abilityStage.md)
- [@ohos.app.ability.ApplicationStateChangeCallback (ApplicationStateChangeCallback)](js-apis-app-ability-applicationStateChangeCallback.md)
- [@ohos.app.ability.common (Context)](js-apis-app-ability-common.md) - [@ohos.app.ability.common (Context)](js-apis-app-ability-common.md)
- [@ohos.app.ability.contextConstant (ContextConstant)](js-apis-app-ability-contextConstant.md) - [@ohos.app.ability.contextConstant (ContextConstant)](js-apis-app-ability-contextConstant.md)
- [@ohos.app.ability.EnvironmentCallback (EnvironmentCallback)](js-apis-app-ability-environmentCallback.md) - [@ohos.app.ability.EnvironmentCallback (EnvironmentCallback)](js-apis-app-ability-environmentCallback.md)
...@@ -151,8 +152,19 @@ ...@@ -151,8 +152,19 @@
- [Common Events of the Bundle Management Subsystem](common_event/commonEvent-bundleManager.md) - [Common Events of the Bundle Management Subsystem](common_event/commonEvent-bundleManager.md)
- [Common Events of the Notification Service](common_event/commonEvent-ans.md) - [Common Events of the Notification Service](common_event/commonEvent-ans.md)
- [Common Events of the Resource Scheduler Subsystem](common_event/commonEvent-resourceschedule.md) - [Common Events of the Resource Scheduler Subsystem](common_event/commonEvent-resourceschedule.md)
- [Common Events of the Window Management Subsystem](common_event/commonEvent-window.md)
- [Common Events of the Network Management Subsystem](common_event/commonEvent-netmanager.md)
- [Common Events of the SMS Application](common_event/commonEvent-mms.md)
- [Common Events of the Telephony Subsystem](common_event/commonEvent-telephony.md) - [Common Events of the Telephony Subsystem](common_event/commonEvent-telephony.md)
- [Common Events of the Power Management Subsystem](common_event/commonEvent-powermgr.md)
- [Common Events of the NFC Subsystem](common_event/commonEvent-nfc.md)
- [Common Events of the Wi-Fi Subsystem](common_event/commonEvent-wifi.md)
- [Common Events of the USB Subsystem](common_event/commonEvent-usb.md) - [Common Events of the USB Subsystem](common_event/commonEvent-usb.md)
- [Common Events of the File Management Subsystem](common_event/commonEvent-filemanagement.md)
- [Common Events of the Theme Framework - Lock Screen](common_event/commonEvent-screenlock.md)
- [Common Events of the Time and Time Zone Subsystem](common_event/commonEvent-time.md)
- [Common Events of the Account Subsystem](common_event/commonEvent-account.md)
- Bundle Management - Bundle Management
- [@ohos.bundle.appControl (appControl)](js-apis-appControl.md) - [@ohos.bundle.appControl (appControl)](js-apis-appControl.md)
- [@ohos.bundle.bundleManager (bundleManager)](js-apis-bundleManager.md) - [@ohos.bundle.bundleManager (bundleManager)](js-apis-bundleManager.md)
...@@ -186,7 +198,10 @@ ...@@ -186,7 +198,10 @@
- UI Page - UI Page
- [@ohos.animator (Animator)](js-apis-animator.md) - [@ohos.animator (Animator)](js-apis-animator.md)
- [@ohos.arkui.componentSnapshot (Component Snapshot)](js-apis-arkui-componentSnapshot.md) - [@ohos.arkui.componentSnapshot (Component Snapshot)](js-apis-arkui-componentSnapshot.md)
- [@ohos.arkui.dragController (DragController)](js-apis-arkui-dragController.md)
- [@ohos.arkui.drawableDescriptor (DrawableDescriptor)](js-apis-arkui-drawableDescriptor.md) - [@ohos.arkui.drawableDescriptor (DrawableDescriptor)](js-apis-arkui-drawableDescriptor.md)
- [@ohos.arkui.inspector (Layout Callback)](js-apis-arkui-inspector.md)
- [@ohos.arkui.UIContext (UIContext)](js-apis-arkui-UIContext.md)
- [@ohos.curves (Interpolation Calculation)](js-apis-curve.md) - [@ohos.curves (Interpolation Calculation)](js-apis-curve.md)
- [@ohos.font (Custom Font Registration)](js-apis-font.md) - [@ohos.font (Custom Font Registration)](js-apis-font.md)
- [@ohos.matrix4 (Matrix Transformation)](js-apis-matrix4.md) - [@ohos.matrix4 (Matrix Transformation)](js-apis-matrix4.md)
...@@ -208,6 +223,7 @@ ...@@ -208,6 +223,7 @@
- webgl - webgl
- [WebGL](js-apis-webgl.md) - [WebGL](js-apis-webgl.md)
- [WebGL2](js-apis-webgl2.md) - [WebGL2](js-apis-webgl2.md)
- Multimedia - Multimedia
- [@ohos.multimedia.audio (Audio Management)](js-apis-audio.md) - [@ohos.multimedia.audio (Audio Management)](js-apis-audio.md)
- [@ohos.multimedia.avsession (AVSession Management)](js-apis-avsession.md) - [@ohos.multimedia.avsession (AVSession Management)](js-apis-avsession.md)
...@@ -267,6 +283,7 @@ ...@@ -267,6 +283,7 @@
- [@ohos.file.fileuri (File URI)](js-apis-file-fileuri.md) - [@ohos.file.fileuri (File URI)](js-apis-file-fileuri.md)
- [@ohos.file.fs (File Management)](js-apis-file-fs.md) - [@ohos.file.fs (File Management)](js-apis-file-fs.md)
- [@ohos.file.hash (File Hash Processing)](js-apis-file-hash.md) - [@ohos.file.hash (File Hash Processing)](js-apis-file-hash.md)
- [@ohos.file.photoAccessHelper (Album Management)](js-apis-photoAccessHelper.md)
- [@ohos.file.picker (File Picker)](js-apis-file-picker.md) - [@ohos.file.picker (File Picker)](js-apis-file-picker.md)
- [@ohos.file.securityLabel (Data Label)](js-apis-file-securityLabel.md) - [@ohos.file.securityLabel (Data Label)](js-apis-file-securityLabel.md)
- [@ohos.file.statvfs (File System Space Statistics)](js-apis-file-statvfs.md) - [@ohos.file.statvfs (File System Space Statistics)](js-apis-file-statvfs.md)
...@@ -275,6 +292,9 @@ ...@@ -275,6 +292,9 @@
- [@ohos.filemanagement.userFileManager (User Data Management)](js-apis-userFileManager.md) - [@ohos.filemanagement.userFileManager (User Data Management)](js-apis-userFileManager.md)
- [@ohos.fileshare (File Sharing)](js-apis-fileShare.md) - [@ohos.fileshare (File Sharing)](js-apis-fileShare.md)
- AI
- [@ohos.ai.mindSporeLite (Inference)](js-apis-mindSporeLite.md)
- Telephony Service - Telephony Service
- [@ohos.contact (Contacts)](js-apis-contact.md) - [@ohos.contact (Contacts)](js-apis-contact.md)
- [@ohos.telephony.call (Call)](js-apis-call.md) - [@ohos.telephony.call (Call)](js-apis-call.md)
...@@ -288,6 +308,7 @@ ...@@ -288,6 +308,7 @@
- [@ohos.net.connection (Network Connection Management)](js-apis-net-connection.md) - [@ohos.net.connection (Network Connection Management)](js-apis-net-connection.md)
- [@ohos.net.ethernet (Ethernet Connection Management)](js-apis-net-ethernet.md) - [@ohos.net.ethernet (Ethernet Connection Management)](js-apis-net-ethernet.md)
- [@ohos.net.http (Data Request)](js-apis-http.md) - [@ohos.net.http (Data Request)](js-apis-http.md)
- [@ohos.net.policy (Network Policy Management)](js-apis-net-policy.md)
- [@ohos.net.mdns (mDNS Management)](js-apis-net-mdns.md) - [@ohos.net.mdns (mDNS Management)](js-apis-net-mdns.md)
- [@ohos.net.sharing (Network Sharing)](js-apis-net-sharing.md) - [@ohos.net.sharing (Network Sharing)](js-apis-net-sharing.md)
- [@ohos.net.socket (Socket Connection)](js-apis-socket.md) - [@ohos.net.socket (Socket Connection)](js-apis-socket.md)
...@@ -296,14 +317,24 @@ ...@@ -296,14 +317,24 @@
- [@ohos.request (Upload and Download)](js-apis-request.md) - [@ohos.request (Upload and Download)](js-apis-request.md)
- Connectivity - Connectivity
- [@ohos.bluetooth.a2dp (Bluetooth a2dp Module)(Recommended)](js-apis-bluetooth-a2dp.md)
- [@ohos.bluetooth.access (Bluetooth access Module)(Recommended)](js-apis-bluetooth-access.md)
- [@ohos.bluetooth.baseProfile (Bluetooth baseProfile Module)(Recommended)](js-apis-bluetooth-baseProfile.md)
- [@ohos.bluetooth.ble (Bluetooth ble Module)(Recommended)](js-apis-bluetooth-ble.md)
- [@ohos.bluetooth.connection (Bluetooth connection Module)(Recommended)](js-apis-bluetooth-connection.md)
- [@ohos.bluetooth.constant (Bluetooth constant Module)(Recommended)](js-apis-bluetooth-constant.md)
- [@ohos.bluetooth.hfp (Bluetooth hfp Module)(Recommended)](js-apis-bluetooth-hfp.md)
- [@ohos.bluetooth.hid (Bluetooth hid Module)(Recommended)(js-apis-bluetooth-hid.md)
- [@ohos.bluetooth.pan (Bluetooth pan Module)(Recommended)](js-apis-bluetooth-pan.md)
- [@ohos.bluetooth.socket (Bluetooth socket Module)(Recommended)](js-apis-bluetooth-socket.md)
- [@ohos.bluetooth (Bluetooth) (To Be Deprecated Soon)](js-apis-bluetooth.md) - [@ohos.bluetooth (Bluetooth) (To Be Deprecated Soon)](js-apis-bluetooth.md)
- [@ohos.bluetoothManager (Bluetooth) (Recommended)](js-apis-bluetoothManager.md) - [@ohos.bluetoothManager (Bluetooth) (To Be Deprecated Soon)](js-apis-bluetoothManager.md)
- [@ohos.connectedTag (Active Tags)](js-apis-connectedTag.md) - [@ohos.connectedTag (Active Tags)](js-apis-connectedTag.md)
- [@ohos.nfc.cardEmulation (Standard NFC Card Emulation)](js-apis-cardEmulation.md) - [@ohos.nfc.cardEmulation (Standard NFC Card Emulation)](js-apis-cardEmulation.md)
- [@ohos.nfc.controller (Standard NFC)](js-apis-nfcController.md) - [@ohos.nfc.controller (Standard NFC)](js-apis-nfcController.md)
- [@ohos.nfc.tag (Standard NFC Tags)](js-apis-nfcTag.md) - [@ohos.nfc.tag (Standard NFC Tags)](js-apis-nfcTag.md)
- [@ohos.rpc (RPC)](js-apis-rpc.md) - [@ohos.rpc (RPC)](js-apis-rpc.md)
- [@ohos.secureElement (SE Channel Management)](js-apis-secureElement.md) - [@ohos.secureElement (SE Management)](js-apis-secureElement.md)
- [@ohos.wifiManager (WLAN) (Recommended)](js-apis-wifiManager.md) - [@ohos.wifiManager (WLAN) (Recommended)](js-apis-wifiManager.md)
- [@ohos.wifiManagerExt (WLAN Extension) (Recommended)](js-apis-wifiManagerExt.md) - [@ohos.wifiManagerExt (WLAN Extension) (Recommended)](js-apis-wifiManagerExt.md)
- [@ohos.wifi (WLAN) (To Be Deprecated Soon)](js-apis-wifi.md) - [@ohos.wifi (WLAN) (To Be Deprecated Soon)](js-apis-wifi.md)
...@@ -318,6 +349,7 @@ ...@@ -318,6 +349,7 @@
- [@ohos.accessibility.GesturePath (Gesture Path)](js-apis-accessibility-GesturePath.md) - [@ohos.accessibility.GesturePath (Gesture Path)](js-apis-accessibility-GesturePath.md)
- [@ohos.accessibility.GesturePoint (Gesture Point)](js-apis-accessibility-GesturePoint.md) - [@ohos.accessibility.GesturePoint (Gesture Point)](js-apis-accessibility-GesturePoint.md)
- [@ohos.application.AccessibilityExtensionAbility (AccessibilityExtensionAbility)](js-apis-application-accessibilityExtensionAbility.md) - [@ohos.application.AccessibilityExtensionAbility (AccessibilityExtensionAbility)](js-apis-application-accessibilityExtensionAbility.md)
- [@ohos.base (Public Callback Information)](js-apis-base.md)
- [@ohos.faultLogger (FaultLogger)](js-apis-faultLogger.md) - [@ohos.faultLogger (FaultLogger)](js-apis-faultLogger.md)
- [@ohos.hichecker (HiChecker)](js-apis-hichecker.md) - [@ohos.hichecker (HiChecker)](js-apis-hichecker.md)
- [@ohos.hidebug (HiDebug)](js-apis-hidebug.md) - [@ohos.hidebug (HiDebug)](js-apis-hidebug.md)
...@@ -337,6 +369,7 @@ ...@@ -337,6 +369,7 @@
- [@ohos.systemDateTime (System Time and Time Zone)](js-apis-system-date-time.md) - [@ohos.systemDateTime (System Time and Time Zone)](js-apis-system-date-time.md)
- [@ohos.systemTimer (System Timer)](js-apis-system-timer.md) - [@ohos.systemTimer (System Timer)](js-apis-system-timer.md)
- [@ohos.wallpaper (Wallpaper)](js-apis-wallpaper.md) - [@ohos.wallpaper (Wallpaper)](js-apis-wallpaper.md)
- [@ohos.WallpaperExtensionAbility (WallpaperExtensionAbility)](js-apis-WallpaperExtensionAbility.md)
- [@ohos.web.webview (Webview)](js-apis-webview.md) - [@ohos.web.webview (Webview)](js-apis-webview.md)
- [Console](js-apis-logs.md) - [Console](js-apis-logs.md)
- [Timer](js-apis-timer.md) - [Timer](js-apis-timer.md)
...@@ -345,6 +378,7 @@ ...@@ -345,6 +378,7 @@
- [AccessibilityExtensionContext](js-apis-inner-application-accessibilityExtensionContext.md) - [AccessibilityExtensionContext](js-apis-inner-application-accessibilityExtensionContext.md)
- Device Management - Device Management
- [@ohos.app.ability.DriverExtensionAbility (DriverExtensionAbility)](js-apis-app-ability-driverExtensionAbility.md)
- [@ohos.batteryInfo (Battery Information)](js-apis-battery-info.md) - [@ohos.batteryInfo (Battery Information)](js-apis-battery-info.md)
- [@ohos.batteryStatistics (Battery Statistics)](js-apis-batteryStatistics.md) - [@ohos.batteryStatistics (Battery Statistics)](js-apis-batteryStatistics.md)
- [@ohos.brightness (Screen Brightness)](js-apis-brightness.md) - [@ohos.brightness (Screen Brightness)](js-apis-brightness.md)
...@@ -356,6 +390,7 @@ ...@@ -356,6 +390,7 @@
- [@ohos.distributedHardware.deviceManager (Device Management)](js-apis-device-manager.md) - [@ohos.distributedHardware.deviceManager (Device Management)](js-apis-device-manager.md)
- [@ohos.driver.deviceManager (Peripheral Management)](js-apis-driver-deviceManager.md) - [@ohos.driver.deviceManager (Peripheral Management)](js-apis-driver-deviceManager.md)
- [@ohos.geoLocationManager (Geolocation Manager)](js-apis-geoLocationManager.md) - [@ohos.geoLocationManager (Geolocation Manager)](js-apis-geoLocationManager.md)
- [@ohos.multimodalInput.gestureEvent (Gesture Input Event)](js-apis-multimodalinput-gestureevent.md)
- [@ohos.multimodalInput.inputConsumer (Input Consumer)](js-apis-inputconsumer.md) - [@ohos.multimodalInput.inputConsumer (Input Consumer)](js-apis-inputconsumer.md)
- [@ohos.multimodalInput.inputDevice (Input Device)](js-apis-inputdevice.md) - [@ohos.multimodalInput.inputDevice (Input Device)](js-apis-inputdevice.md)
- [@ohos.multimodalInput.inputDeviceCooperate (Screen Hopping) (To Be Deprecated Soon)](js-apis-cooperate.md) - [@ohos.multimodalInput.inputDeviceCooperate (Screen Hopping) (To Be Deprecated Soon)](js-apis-cooperate.md)
...@@ -380,10 +415,12 @@ ...@@ -380,10 +415,12 @@
- [@ohos.update (Update)](js-apis-update.md) - [@ohos.update (Update)](js-apis-update.md)
- [@ohos.usbManager (USB Manager)](js-apis-usbManager.md) - [@ohos.usbManager (USB Manager)](js-apis-usbManager.md)
- [@ohos.vibrator (Vibrator)](js-apis-vibrator.md) - [@ohos.vibrator (Vibrator)](js-apis-vibrator.md)
- application
- [DriverExtensionContext](js-apis-inner-application-driverExtensionContext.md)
- Account Management - Account Management
- [@ohos.account.appAccount (App Account Management)](js-apis-appAccount.md) - [@ohos.account.appAccount (App Account Management)](js-apis-appAccount.md)
- [@ohos.account.appAccount.AuthorizationExtensionAbility (App Account AuthorizationExtensionAbility)](js-apis-appAccount-authorizationExtensionAbility.md) - [@ohos.account.appAccount.AuthorizationExtensionAbility (App AuthorizationExtensionAbility)](js-apis-appAccount-authorizationExtensionAbility.md)
- [@ohos.account.distributedAccount (Distributed Account Management)](js-apis-distributed-account.md) - [@ohos.account.distributedAccount (Distributed Account Management)](js-apis-distributed-account.md)
- [@ohos.account.osAccount (OS Account Management)](js-apis-osAccount.md) - [@ohos.account.osAccount (OS Account Management)](js-apis-osAccount.md)
...@@ -391,6 +428,7 @@ ...@@ -391,6 +428,7 @@
- [@ohos.configPolicy (Configuration Policy)](js-apis-configPolicy.md) - [@ohos.configPolicy (Configuration Policy)](js-apis-configPolicy.md)
- Enterprise Device Management - Enterprise Device Management
- [Enterprise Device Management Overview (for System Applications Only)](enterpriseDeviceManagement-overview.md)
- [@ohos.enterprise.accountManager(Account Management)](js-apis-enterprise-accountManager.md) - [@ohos.enterprise.accountManager(Account Management)](js-apis-enterprise-accountManager.md)
- [@ohos.enterprise.adminManager (Enterprise Device Management)](js-apis-enterprise-adminManager.md) - [@ohos.enterprise.adminManager (Enterprise Device Management)](js-apis-enterprise-adminManager.md)
- [@ohos.enterprise.applicationManager (Application Management)](js-apis-enterprise-applicationManager.md) - [@ohos.enterprise.applicationManager (Application Management)](js-apis-enterprise-applicationManager.md)
......
# @ohos.bluetooth.a2dp (Bluetooth A2DP Module)
The **a2dp** module provides APIs for using the Bluetooth Advanced Audio Distribution Profile (A2DP), which defines how to stream high quality audio from one device to another over a Bluetooth connection.
> **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.
## Modules to Import
```js
import a2dp from '@ohos.bluetooth.a2dp';
```
## a2dp.createA2dpSrcProfile<a name="createA2dpSrcProfile"></a>
createA2dpSrcProfile(): A2dpSourceProfile
Creates an **A2dpSrcProfile** instance.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ----------------------------- | ---------- |
| A2dpSourceProfile | **A2dpSrcProfile** instance created.|
**Example**
```js
try {
let a2dpProfile = a2dp.createA2dpSrcProfile();
console.info('a2dp success');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## A2dpSourceProfile
Provides APIs for using the A2DP. Before using any API of **A2dpSourceProfile**, you need to create an instance of this class by using **createA2dpSrcProfile()**.
### connect<a name="a2dp-connect"></a>
connect(deviceId: string): void
Connects to an A2DP device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| deviceId | string | Yes | Address of the device to connect. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
a2dpSrc.connect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### disconnect<a name="a2dp-disconnect"></a>
disconnect(deviceId: string): void
Disconnects from an A2DP device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| deviceId | string | Yes | Address of the device to disconnect. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### getPlayingState
getPlayingState(deviceId: string): PlayingState
Obtains the playing state of a device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the remote device.|
**Return value**
| Type | Description |
| ----------------------------- | ---------- |
| [PlayingState](#PlayingState) | Playing state of the remote device obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let state = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## PlayingState<a name="PlayingState"></a>
Enumerates the A2DP playing states.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ----------------- | ------ | ------- |
| STATE_NOT_PLAYING | 0x0000 | Not playing. |
| STATE_PLAYING | 0x0001 | Playing.|
# @ohos.bluetooth.access (Bluetooth Access Module)
The **access** module provides APIs for enabling and disabling Bluetooth and obtaining the Bluetooth status.
> **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.
## Modules to Import
```js
import access from '@ohos.bluetooth.access';
```
## access.enableBluetooth<a name="enableBluetooth"></a>
enableBluetooth(): void
Enables Bluetooth.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message |
| -------- | ------------------ |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
try {
access.enableBluetooth();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## access.disableBluetooth<a name="disableBluetooth"></a>
disableBluetooth(): void
Disables Bluetooth.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
|ID | Error Message |
| -------- | ------------------ |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
try {
access.disableBluetooth();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## access.getState<a name="getState"></a>
getState(): BluetoothState
Obtains the Bluetooth state.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| --------------------------------- | ---------------- |
| [BluetoothState](#bluetoothstate) | Bluetooth state obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
|ID | Error Message |
| -------- | ------------------ |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
try {
let state = access.getState();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## access.on('stateChange')<a name="stateChange"></a>
on(type: "stateChange", callback: Callback&lt;BluetoothState&gt;): void
Subscribes to Bluetooth state changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------------------------- | ----- | ---------------------------------------------------------- |
| type | string | Yes | Event type. The value is **stateChange**, which indicates a Bluetooth state change event. |
| callback | Callback&lt;[BluetoothState](#bluetoothstate)&gt; | Yes | Callback invoked to return the Bluetooth state. You need to implement this callback.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
|ID | Error Message |
| -------- | ------------------ |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bluetooth state = '+ JSON.stringify(data));
}
try {
access.on('stateChange', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## access.off('stateChange')<a name="stateChange"></a>
off(type: "stateChange", callback?: Callback&lt;BluetoothState&gt;): void
Unsubscribes from Bluetooth state changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **stateChange**, which indicates a Bluetooth state change event. |
| callback | Callback&lt;[BluetoothState](#bluetoothstate)&gt; | No | Callback for the Bluetooth state change event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bluetooth state = '+ JSON.stringify(data));
}
try {
access.on('stateChange', onReceiveEvent);
access.off('stateChange', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## BluetoothState<a name="BluetoothState"></a>
Enumerates the Bluetooth states.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| --------------------- | ---- | ------------------ |
| STATE_OFF | 0 | Bluetooth is turned off. |
| STATE_TURNING_ON | 1 | Bluetooth is being turned on. |
| STATE_ON | 2 | Bluetooth is turned on. |
| STATE_TURNING_OFF | 3 | Bluetooth is being turned off. |
| STATE_BLE_TURNING_ON | 4 | The LE-only mode is being turned on for Bluetooth.|
| STATE_BLE_ON | 5 | Bluetooth is in LE-only mode. |
| STATE_BLE_TURNING_OFF | 6 | The LE-only mode is being turned off for Bluetooth.|
# @ohos.bluetooth.baseProfile (Bluetooth baseProfile Module)
The **baseProfile** module provides APIs for using basic Bluetooth profiles.
> **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.
## Modules to Import
```js
import baseProfile from '@ohos.bluetooth.baseProfile';
```
## ConnectionStrategy<a name="ConnectionStrategy"></a>
Enumerates the profile connection strategies.
**System API**: This is a system API.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| -------------------------------- | ------ | --------------- |
| CONNECTION_STRATEGY_UNSUPPORTED | 0 | Default connection strategy to use when the device is not paired.<br>This is a system API.|
| CONNECTION_STRATEGY_ALLOWED | 1 | Connection strategy to use when the device is allowed to accept or initiate pairing.<br>This is a system API.|
| CONNECTION_STRATEGY_FORBIDDEN | 2 | Connection strategy to use when the device is not allowed to accept or initiate pairing.<br>This is a system API. |
## StateChangeParam<a name="StateChangeParam"></a>
Represents the profile state change parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable| Writable| Description |
| -------- | ----------------------------- | ---- | ---- | ------------------------------- |
| deviceId | string | Yes | No | Address of the Bluetooth device. |
| state | ProfileConnectionState | Yes | No | Profile connection state of the device.|
## baseProfile.setConnectionStrategy<a name="setConnectionStrategy"></a>
setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy, callback: AsyncCallback&lt;void&gt;): void
Sets the profile connection strategy for this device. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX. |
| strategy | [ConnectionStrategy](#connectionstrategy) | Yes |Profile connection strategy to set.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let setRet = a2dpSrc.setConnectionStrategy('XX:XX:XX:XX:XX:XX', 0, (err, data) => {
console.info('setConnectionStrategy, err: ' + JSON.stringify(err) + ', data: ' + JSON.stringify(data));
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## baseProfile.setConnectionStrategy<a name="setConnectionStrategy"></a>
setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy): Promise&lt;void&gt;
Sets the profile connection strategy for this device. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX. |
| strategy | [ConnectionStrategy](#connectionstrategy) | Yes |Profile connection strategy to set.|
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let setRet = a2dpSrc.setConnectionStrategy('XX:XX:XX:XX:XX:XX', 1).then((data) => {
console.info('setConnectionStrategy');
}, (err) => {
console.error('setConnectionStrategy errCode: ' + err.code + ', errMessage: ' + err.message);
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## baseProfile.getConnectionStrategy<a name="getConnectionStrategy"></a>
getConnectionStrategy(deviceId: string, callback: AsyncCallback&lt;ConnectionStrategy&gt;): void
Obtains the profile connection strategy. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX. |
| callback | AsyncCallback&lt;[ConnectionStrategy](#connectionstrategy)&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let setRet = a2dpSrc.getConnectionStrategy('XX:XX:XX:XX:XX:XX', 0, (err, data) => {
console.info('getConnectionStrategy, err: ' + JSON.stringify(err) + ', data: ' + JSON.stringify(data));
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## baseProfile.getConnectionStrategy<a name="getConnectionStrategy"></a>
getConnectionStrategy(deviceId: string): Promise&lt;ConnectionStrategy&gt;
Obtains the profile connection strategy. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX. |
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;[ConnectionStrategy](#connectionstrategy)&gt; | Promise used to return the profile connection strategy obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let setRet = a2dpSrc.getConnectionStrategy('XX:XX:XX:XX:XX:XX', 1).then((data) => {
console.info('getConnectionStrategy');
}, (error) => {
console.error('getConnectionStrategy errCode: ' + err.code + ', errMessage: ' + err.message);
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## baseProfile.getConnectedDevices<a name="getConnectedDevices"></a>
getConnectedDevices(): Array&lt;string&gt;
Obtains the connected devices.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ------------------- | ------------------- |
| Array&lt;string&gt; | Addresses of the connected devices.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let retArray = a2dpSrc.getConnectedDevices();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## baseProfile.getConnectionState<a name="getConnectionState"></a>
getConnectionState(deviceId: string): ProfileConnectionState
Obtains the profile connection state of a device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| deviceId | string | Yes | Address of the remote device.|
**Return value**
| Type | Description |
| ------------------------------------------------- | ----------------------- |
| [ProfileConnectionState](js-apis-bluetooth-constant.md#profileconnectionstate) | Profile connection state obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let ret = a2dpSrc.getConnectionState('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## baseProfile.on('connectionStateChange')
on(type: 'connectionStateChange', callback: Callback&lt;StateChangeParam&gt;): void
Subscribes to profile connection state changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **connectionStateChange**, which indicates a profile connection state change event.|
| callback | Callback&lt;[StateChangeParam](#statechangeparam)&gt; | Yes | Callback invoked to return the profile connection state change. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
function onReceiveEvent(data) {
console.info('a2dp state = '+ JSON.stringify(data));
}
let a2dpSrc = a2dp.createA2dpSrcProfile();
a2dpSrc.on('connectionStateChange', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## baseProfile.off('connectionStateChange')
off(type: 'connectionStateChange', callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from profile connection state changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **connectionStateChange**, which indicates a profile connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the profile connection state change. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
function onReceiveEvent(data) {
console.info('a2dp state = '+ JSON.stringify(data));
}
let a2dpSrc = a2dp.createA2dpSrcProfile();
a2dpSrc.on('connectionStateChange', onReceiveEvent);
a2dpSrc.off('connectionStateChange', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
# @ohos.bluetooth.ble (Bluetooth BLE Module)
The **ble** module provides APIs for accessing the Bluetooth personal area network.
> **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.
## Modules to Import
```js
import ble from '@ohos.bluetooth.ble';
```
## ble.createGattServer<a name="createGattServer"></a>
createGattServer(): GattServer
Creates a **GattServer** instance.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ----------------------------- | ---------- |
| GattServer | **GattServer** instance created.|
**Example**
```js
let gattServer = ble.createGattServer();
console.info('gatt success');
```
## ble.createGattClientDevice<a name="createGattClientDevice"></a>
createGattClientDevice(deviceId: string): GattClientDevice
Creates a **GattClientDevice** instance.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------------------------------ |
| deviceId | string | Yes | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
**Return value**
| Type | Description |
| ------------------------------------- | ------------------------------------ |
| [GattClientDevice](#gattclientdevice) | **GattClientDevice** instance created. Before using an API of the client, you must create a **GattClientDevice** instance.|
**Example**
```js
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## ble.getConnectedBLEDevices<a name="getConnectedBLEDevices"></a>
getConnectedBLEDevices(): Array&lt;string&gt;
Obtains the Bluetooth Low Energy (BLE) devices connected to this device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ------------------- | ------------------- |
| Array&lt;string&gt; | Addresses of the BLE devices connected to this device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let result = ble.getConnectedBLEDevices();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## ble.startBLEScan<a name="startBLEScan"></a>
startBLEScan(filters: Array&lt;ScanFilter&gt;, options?: ScanOptions): void
Starts a BLE scan.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | -------------------------------------- | ---- | ----------------------------------- |
| filters | Array&lt;[ScanFilter](#scanfilter)&gt; | Yes | Criteria for filtering the scan result. Set this parameter to **null** if you do not want to filter the scan result.|
| options | [ScanOptions](#scanoptions) | No | Scan options. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('BLE scan device find result = '+ JSON.stringify(data));
}
try {
ble.on("BLEDeviceFind", onReceiveEvent);
ble.startBLEScan(
[{
deviceId:"XX:XX:XX:XX:XX:XX",
name:"test",
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"
}],
{
interval: 500,
dutyMode: ble.ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: ble.MatchMode.MATCH_MODE_AGGRESSIVE,
}
);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## ble.stopBLEScan<a name="stopBLEScan"></a>
stopBLEScan(): void
Stops the BLE scan.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
ble.stopBLEScan();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## ble.startAdvertising<a name="startAdvertising"></a>
startAdvertising(setting: AdvertiseSetting, advData: AdvertiseData, advResponse?: AdvertiseData): void
Starts BLE advertising.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------------------------------------- | ---- | -------------- |
| setting | [AdvertiseSetting](#advertisesetting) | Yes | Settings related to BLE advertising. |
| advData | [AdvertiseData](#advertisedata) | Yes | Content of the BLE advertisement packet. |
| advResponse | [AdvertiseData](#advertisedata) | No | Response to the BLE scan request.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
console.info('manufactureValueBuffer = '+ JSON.stringify(manufactureValueBuffer));
console.info('serviceValueBuffer = '+ JSON.stringify(serviceValueBuffer));
try {
ble.startAdvertising({
interval:150,
txPower:0,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## ble.stopAdvertising<a name="stopAdvertising"></a>
stopAdvertising(): void
Stops BLE advertising.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
ble.stopAdvertising();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## ble.on('BLEDeviceFind')
on(type: 'BLEDeviceFind', callback: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
Subscribes to BLE device discovery events.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
| type | string | Yes | Event type. The value is **BLEDeviceFind**, which indicates an event of discovering a BLE device. |
| callback | Callback&lt;Array&lt;[ScanResult](#scanresult)&gt;&gt; | Yes | Callback invoked to return the discovered devices. You need to implement this callback.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bluetooth device find = '+ JSON.stringify(data));
}
try {
ble.on('BLEDeviceFind', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## ble.off('BLEDeviceFind')
off(type: 'BLEDeviceFind', callback?: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
Unsubscribes from BLE device discovery events.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **BLEDeviceFind**, which indicates an event of discovering a BLE device. |
| callback | Callback&lt;Array&lt;[ScanResult](#scanresult)&gt;&gt; | No | Callback for the **BLEDeviceFind** event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bluetooth device find = '+ JSON.stringify(data));
}
try {
ble.on('BLEDeviceFind', onReceiveEvent);
ble.off('BLEDeviceFind', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## GattServer
Implements the Generic Attribute Profile (GATT) server. Before using an API of this class, you need to create a **GattServer** instance using **createGattServer()**.
### addService
addService(service: GattService): void
Adds a service to this GATT server.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | --------------------------- | ---- | ------------------------ |
| service | [GattService](#gattservice) | Yes | Service to add. Settings related to BLE advertising.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
// Create descriptors.
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
// Create characteristics.
let characteristics = [];
let arrayBufferC = new ArrayBuffer(8);
let cccV = new Uint8Array(arrayBufferC);
cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
let characteristicN = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic;
// Create a gattService instance.
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, characteristics:characteristics, includeServices:[]};
try {
gattServer.addService(gattService);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### removeService
removeService(serviceUuid: string): void
Removes a service from this GATT server.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | ---------------------------------------- |
| serviceUuid | string | Yes | Universally unique identifier (UUID) of the service to remove, for example, **00001810-0000-1000-8000-00805F9B34FB**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
let server = ble.createGattServer();
try {
server.removeService('00001810-0000-1000-8000-00805F9B34FB');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### close
close(): void
Closes this GATT server to unregister it from the protocol stack. The closed [GattServer](#gattserver) instance will no longer be used.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
let server = ble.createGattServer();
try {
server.close();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### notifyCharacteristicChanged
notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic, callback: AsyncCallback&lt;void&gt;): void
Notifies a connected client device when a characteristic value changes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------------- | ---------------------------------------- | ---- | --------------------------------------- |
| deviceId | string | Yes | Address of the client that receives the notifications, for example, XX:XX:XX:XX:XX:XX.|
| notifyCharacteristic | [NotifyCharacteristic](#notifycharacteristic) | Yes | New characteristic value. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
let arrayBufferC = new ArrayBuffer(8);
let notifyCharacter = {
"serviceUuid": '00001810-0000-1000-8000-00805F9B34FB',
"characteristicUuid": '00001820-0000-1000-8000-00805F9B34FB',
"characteristicValue": arrayBufferC,
"confirm": true,
};
try {
gattServer.notifyCharacteristicChanged('XX:XX:XX:XX:XX:XX', notifyCharacter, (err) => {
if (err) {
console.info('notifyCharacteristicChanged callback failed');
} else {
console.info('notifyCharacteristicChanged callback successful');
}
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### notifyCharacteristicChanged
notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic): Promise&lt;void&gt;
Notifies a connected client device when a characteristic value changes. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------------- | ---------------------------------------- | ---- | --------------------------------------- |
| deviceId | string | Yes | Address of the client that receives the notifications, for example, XX:XX:XX:XX:XX:XX.|
| notifyCharacteristic | [NotifyCharacteristic](#notifycharacteristic) | Yes | New characteristic value. |
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
let arrayBufferC = new ArrayBuffer(8);
let notifyCharacter = {
"serviceUuid": '00001810-0000-1000-8000-00805F9B34FB',
"characteristicUuid": '00001820-0000-1000-8000-00805F9B34FB',
"characteristicValue": arrayBufferC,
"confirm": true,
};
try {
gattServer.notifyCharacteristicChanged('XX:XX:XX:XX:XX:XX', notifyCharacter).then(() => {
console.info('notifyCharacteristicChanged promise successfull');
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### sendResponse
sendResponse(serverResponse: ServerResponse): void
Sends a response to a read or write request from the GATT client.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | --------------------------------- | ---- | --------------- |
| serverResponse | [ServerResponse](#serverresponse) | Yes | Response returned by the GATT server.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
/* send response */
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 1123;
let serverResponse = {
'deviceId': 'XX:XX:XX:XX:XX:XX',
'transId': 0,
'status': 0,
'offset': 0,
'value': arrayBufferCCC,
};
try {
gattServer.sendResponse(serverResponse);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### on('characteristicRead')
on(type: 'characteristicRead', callback: Callback&lt;CharacteristicReadRequest&gt;): void
Subscribes to characteristic read request events.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------------- |
| type | string | Yes | Event type. The value is **characteristicRead**, which indicates a characteristic read request event.|
| callback | Callback&lt;[CharacteristicReadRequest](#characteristicreadrequest)&gt; | Yes | Callback invoked to return a characteristic read request event from the GATT client. |
**Example**
```js
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 1123;
function ReadCharacteristicReq(CharacteristicReadRequest) {
let deviceId = CharacteristicReadRequest.deviceId;
let transId = CharacteristicReadRequest.transId;
let offset = CharacteristicReadRequest.offset;
let characteristicUuid = CharacteristicReadRequest.characteristicUuid;
let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC};
try {
gattServer.sendResponse(serverResponse);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
}
gattServer.on('characteristicRead', ReadCharacteristicReq);
```
### off('characteristicRead')
off(type: 'characteristicRead', callback?: Callback&lt;CharacteristicReadRequest&gt;): void
Unsubscribes from characteristic read request events.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **characteristicRead**, which indicates a characteristic read request event. |
| callback | Callback&lt;[CharacteristicReadRequest](#characteristicreadrequest)&gt; | No | Callback for the characteristic read request event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
gattServer.off('characteristicRead');
```
### on('characteristicWrite')
on(type: 'characteristicWrite', callback: Callback&lt;CharacteristicWriteRequest&gt;): void
Subscribes to characteristic write request events.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| type | string | Yes | Event type. The value **characteristicWrite** indicates a characteristic write request event.|
| callback | Callback&lt;[CharacteristicWriteRequest](#characteristicwriterequest)&gt; | Yes | Callback invoked to return a characteristic write request from the GATT client. |
**Example**
```js
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
function WriteCharacteristicReq(CharacteristicWriteRequest) {
let deviceId = CharacteristicWriteRequest.deviceId;
let transId = CharacteristicWriteRequest.transId;
let offset = CharacteristicWriteRequest.offset;
let isPrepared = CharacteristicWriteRequest.isPrepared;
let needRsp = CharacteristicWriteRequest.needRsp;
let value = new Uint8Array(CharacteristicWriteRequest.value);
let characteristicUuid = CharacteristicWriteRequest.characteristicUuid;
cccValue[0] = value[0];
let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC};
try {
gattServer.sendResponse(serverResponse);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
}
gattServer.on('characteristicWrite', WriteCharacteristicReq);
```
### off('characteristicWrite')
off(type: 'characteristicWrite', callback?: Callback&lt;CharacteristicWriteRequest&gt;): void
Unsubscribes from characteristic write request events.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **characteristicWrite**, which indicates a characteristic write request event. |
| callback | Callback&lt;[CharacteristicWriteRequest](#characteristicwriterequest)&gt; | No | Callback for the characteristic write request event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
gattServer.off('characteristicWrite');
```
### on('descriptorRead')
on(type: 'descriptorRead', callback: Callback&lt;DescriptorReadRequest&gt;): void
Subscribes to descriptor read request events.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------------- |
| type | string | Yes | Event type. The value is **descriptorRead**, which indicates a descriptor read request event.|
| callback | Callback&lt;[DescriptorReadRequest](#descriptorreadrequest)&gt; | Yes | Callback invoked to return a descriptor read request event from the GATT client. |
**Example**
```js
let arrayBufferDesc = new ArrayBuffer(8);
let descValue = new Uint8Array(arrayBufferDesc);
descValue[0] = 1101;
function ReadDescriptorReq(DescriptorReadRequest) {
let deviceId = DescriptorReadRequest.deviceId;
let transId = DescriptorReadRequest.transId;
let offset = DescriptorReadRequest.offset;
let descriptorUuid = DescriptorReadRequest.descriptorUuid;
let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferDesc};
try {
gattServer.sendResponse(serverResponse);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
}
gattServer.on('descriptorRead', ReadDescriptorReq);
```
### off('descriptorRead')
off(type: 'descriptorRead', callback?: Callback&lt;DescriptorReadRequest&gt;): void
Unsubscribes from descriptor read request events.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **descriptorRead**, which indicates a descriptor read request event. |
| callback | Callback&lt;[DescriptorReadRequest](#descriptorreadrequest)&gt; | No | Callback for the descriptor read request event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
gattServer.off('descriptorRead');
```
### on('descriptorWrite')
on(type: 'descriptorWrite', callback: Callback&lt;DescriptorWriteRequest&gt;): void
Subscribes to descriptor write request events.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------- |
| type | string | Yes | Event type. The value is **descriptorWrite**, which indicates a descriptor write request event.|
| callback | Callback&lt;[DescriptorWriteRequest](#descriptorwriterequest)&gt; | Yes | Callback invoked to return a descriptor write request from the GATT client. |
**Example**
```js
let arrayBufferDesc = new ArrayBuffer(8);
let descValue = new Uint8Array(arrayBufferDesc);
function WriteDescriptorReq(DescriptorWriteRequest) {
let deviceId = DescriptorWriteRequest.deviceId;
let transId = DescriptorWriteRequest.transId;
let offset = DescriptorWriteRequest.offset;
let isPrepared = DescriptorWriteRequest.isPrepared;
let needRsp = DescriptorWriteRequest.needRsp;
let value = new Uint8Array(DescriptorWriteRequest.value);
let descriptorUuid = DescriptorWriteRequest.descriptorUuid;
descValue[0] = value[0];
let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferDesc};
try {
gattServer.sendResponse(serverResponse);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
}
gattServer.on('descriptorRead', WriteDescriptorReq);
```
### off('descriptorWrite')
off(type: 'descriptorWrite', callback?: Callback&lt;DescriptorWriteRequest&gt;): void
Unsubscribes from descriptor write request events.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **descriptorWrite**, which indicates a descriptor write request event. |
| callback | Callback&lt;[DescriptorWriteRequest](#descriptorwriterequest)&gt; | No | Callback for the descriptor write request event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
gattServer.off('descriptorWrite');
```
### on('connectionStateChange')
on(type: 'connectionStateChange', callback: Callback&lt;BLEConnectionChangeState&gt;): void
Subscribes to BLE connection state change events.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **connectionStateChange**, which indicates a BLE connection state change event.|
| callback | Callback&lt;[BLEConnectionChangeState](#bleconnectionchangestate)&gt; | Yes | Callback invoked to return the BLE connection state. |
**Example**
```js
function Connected(BLEConnectionChangeState) {
let deviceId = BLEConnectionChangeState.deviceId;
let status = BLEConnectionChangeState.state;
}
gattServer.on('connectionStateChange', Connected);
```
### off('connectionStateChange')
off(type: 'connectionStateChange', callback?: Callback&lt;BLEConnectionChangeState&gt;): void
Unsubscribes from BLE connection state changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **connectionStateChange**, which indicates a BLE connection state change event.|
| callback | Callback&lt;[BLEConnectionChangeState](#bleconnectionchangestate)&gt; | No | Callback for the BLE connection state change event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
gattServer.off('connectionStateChange');
```
## GattClientDevice
Implements the GATT client. Before using an API of this class, you must create a **GattClientDevice** instance using **createGattClientDevice(deviceId: string)**.
### connect
connect(): void
Connects to the remote BLE device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.connect();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### disconnect
disconnect(): void
Disconnects from the remote BLE device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.disconnect();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### close
close(): void
Closes this GATT client to unregister it from the protocol stack. The closed [GattClientDevice](#gattclientdevice) instance will no longer be used.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.close();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### getDeviceName
getDeviceName(callback: AsyncCallback&lt;string&gt;): void
Obtains the name of the remote BLE device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the remote BLE device name obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
// callback
try {
let gattClient = ble.createGattClientDevice("XX:XX:XX:XX:XX:XX");
gattClient.connect();
let deviceName = gattClient.getDeviceName((err, data)=> {
console.info('device name err ' + JSON.stringify(err));
console.info('device name' + JSON.stringify(data));
})
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### getDeviceName
getDeviceName(): Promise&lt;string&gt;
Obtains the name of the remote BLE device. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| --------------------- | ---------------------------------- |
| Promise&lt;string&gt; | Promise used to return the remote BLE device name.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
// promise
try {
let gattClient = ble.createGattClientDevice("XX:XX:XX:XX:XX:XX");
gattClient.connect();
let deviceName = gattClient.getDeviceName().then((data) => {
console.info('device name' + JSON.stringify(data));
})
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### getServices
getServices(callback: AsyncCallback&lt;Array&lt;GattService&gt;&gt;): void
Obtains all services of the remote BLE device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback&lt;Array&lt;[GattService](#gattservice)&gt;&gt; | Yes | Callback invoked to return the services obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
// Callback
function getServices(code, gattServices) {
if (code.code == 0) {
let services = gattServices;
console.log('bluetooth code is ' + code.code);
console.log('bluetooth services size is ', services.length);
for (let i = 0; i < services.length; i++) {
console.log('bluetooth serviceUuid is ' + services[i].serviceUuid);
}
}
}
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.connect();
device.getServices(getServices);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### getServices
getServices(): Promise&lt;Array&lt;GattService&gt;&gt;
Obtains all services of the remote BLE device. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ---------------------------------------- | --------------------------- |
| Promise&lt;Array&lt;[GattService](#gattservice)&gt;&gt; | Promise used to return the services obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
// Promise
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.connect();
device.getServices().then(result => {
console.info('getServices successfully:' + JSON.stringify(result));
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### readCharacteristicValue
readCharacteristicValue(characteristic: BLECharacteristic, callback: AsyncCallback&lt;BLECharacteristic&gt;): void
Reads the characteristic value of the specific service of the remote BLE device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | ---------------------------------------- | ---- | ----------------------- |
| characteristic | [BLECharacteristic](#blecharacteristic) | Yes | Characteristic value to read. |
| callback | AsyncCallback&lt;[BLECharacteristic](#blecharacteristic)&gt; | Yes | Callback invoked to return the characteristic value read.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901000 | Read forbidden. |
|2900099 | Operation failed. |
**Example**
```js
function readCcc(code, BLECharacteristic) {
if (code.code != 0) {
return;
}
console.log('bluetooth characteristic uuid: ' + BLECharacteristic.characteristicUuid);
let value = new Uint8Array(BLECharacteristic.characteristicValue);
console.log('bluetooth characteristic value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
}
let descriptors = [];
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
descriptors[0] = descriptor;
let bufferCCC = new ArrayBuffer(8);
let cccV = new Uint8Array(bufferCCC);
cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: bufferCCC, descriptors:descriptors};
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.readCharacteristicValue(characteristic, readCcc);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### readCharacteristicValue
readCharacteristicValue(characteristic: BLECharacteristic): Promise&lt;BLECharacteristic&gt;
Reads the characteristic value of the specific service of the remote BLE device. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | --------------------------------------- | ---- | -------- |
| characteristic | [BLECharacteristic](#blecharacteristic) | Yes | Characteristic value to read.|
**Return value**
| Type | Description |
| ---------------------------------------- | -------------------------- |
| Promise&lt;[BLECharacteristic](#blecharacteristic)&gt; | Promise used to return the characteristic value read.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901000 | Read forbidden. |
|2900099 | Operation failed. |
**Example**
```js
let descriptors = [];
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
descriptors[0] = descriptor;
let bufferCCC = new ArrayBuffer(8);
let cccV = new Uint8Array(bufferCCC);
cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: bufferCCC, descriptors:descriptors};
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.readCharacteristicValue(characteristic);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### readDescriptorValue
readDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback&lt;BLEDescriptor&gt;): void
Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ---------------------------------------- | ---- | ----------------------- |
| descriptor | [BLEDescriptor](#bledescriptor) | Yes | Descriptor to read. |
| callback | AsyncCallback&lt;[BLEDescriptor](#bledescriptor)&gt; | Yes | Callback invoked to return the descriptor read.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901000 | Read forbidden. |
|2900099 | Operation failed. |
**Example**
```js
function readDesc(code, BLEDescriptor) {
if (code.code != 0) {
return;
}
console.log('bluetooth descriptor uuid: ' + BLEDescriptor.descriptorUuid);
let value = new Uint8Array(BLEDescriptor.descriptorValue);
console.log('bluetooth descriptor value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
}
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 11;
let descriptor = {
serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB',
descriptorValue: bufferDesc
};
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.readDescriptorValue(descriptor, readDesc);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### readDescriptorValue
readDescriptorValue(descriptor: BLEDescriptor): Promise&lt;BLEDescriptor&gt;
Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------------------------------- | ---- | -------- |
| descriptor | [BLEDescriptor](#bledescriptor) | Yes | Descriptor to read.|
**Return value**
| Type | Description |
| ---------------------------------------- | -------------------------- |
| Promise&lt;[BLEDescriptor](#bledescriptor)&gt; | Promise used to return the descriptor read.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901000 | Read forbidden. |
|2900099 | Operation failed. |
**Example**
```js
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 11;
let descriptor = {
serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB',
descriptorValue: bufferDesc
};
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.readDescriptorValue(descriptor);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### writeCharacteristicValue
writeCharacteristicValue(characteristic: BLECharacteristic, writeType: GattWriteType, callback: AsyncCallback&lt;void&gt;): void
Writes a characteristic value to the remote BLE device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | --------------------------------------- | ---- | ------------------- |
| characteristic | [BLECharacteristic](#blecharacteristic) | Yes | Binary value and other parameters of the BLE device characteristic.|
| writeType | GattWriteType | Yes | Write type of the Bluetooth device characteristic value.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the write operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901001 | Write forbidden. |
|2900099 | Operation failed. |
**Example**
```js
let descriptors = [];
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
descriptors[0] = descriptor;
let bufferCCC = new ArrayBuffer(8);
let cccV = new Uint8Array(bufferCCC);
cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: bufferCCC, descriptors:descriptors};
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.writeCharacteristicValue(characteristic);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### writeCharacteristicValue
writeCharacteristicValue(characteristic: BLECharacteristic, writeType: GattWriteType): Promise&lt;void&gt;
Writes a characteristic value to the remote BLE device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | --------------------------------------- | ---- | ------------------- |
| characteristic | [BLECharacteristic](#blecharacteristic) | Yes | Binary value and other parameters of the BLE device characteristic.|
| writeType | GattWriteType | Yes | Write type of the Bluetooth device characteristic value.|
**Return value**
| Type | Description |
| ---------------------------------------- | -------------------------- |
| Promise&lt;void&gt; | Promise used to return the descriptor read.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901001 | Write forbidden. |
|2900099 | Operation failed. |
**Example**
```js
let descriptors = [];
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
descriptors[0] = descriptor;
let bufferCCC = new ArrayBuffer(8);
let cccV = new Uint8Array(bufferCCC);
cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: bufferCCC, descriptors:descriptors};
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.writeCharacteristicValue(characteristic);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### writeDescriptorValue
writeDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback&lt;void&gt;): void
Writes binary data to the specific descriptor of the remote BLE device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------------------------------- | ---- | ------------------ |
| descriptor | [BLEDescriptor](#bledescriptor) | Yes | Binary value and other parameters of the BLE device descriptor.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the write operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901001 | Write forbidden. |
|2900099 | Operation failed. |
**Example**
```js
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 22;
let descriptor = {
serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB',
descriptorValue: bufferDesc
};
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.writeDescriptorValue(descriptor);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### writeDescriptorValue
writeDescriptorValue(descriptor: BLEDescriptor): Promise&lt;void&gt;
Writes binary data to the specific descriptor of the remote BLE device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------------------------------- | ---- | ------------------ |
| descriptor | [BLEDescriptor](#bledescriptor) | Yes | Binary value and other parameters of the BLE device descriptor.|
**Return value**
| Type | Description |
| ---------------------------------------- | -------------------------- |
| Promise&lt;void&gt; | Promise used to return the descriptor read.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901001 | Write forbidden. |
|2900099 | Operation failed. |
**Example**
```js
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 22;
let descriptor = {
serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB',
descriptorValue: bufferDesc
};
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.writeDescriptorValue(descriptor);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### getRssiValue
getRssiValue(callback: AsyncCallback&lt;number&gt;): void
Obtains the RSSI of the remote BLE device. This API uses an asynchronous callback to return the result. It can be used only after a connection is set up by calling [connect](#connect).
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the RSSI, in dBm.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
// callback
try {
let gattClient = ble.createGattClientDevice("XX:XX:XX:XX:XX:XX");
gattClient.connect();
let rssi = gattClient.getRssiValue((err, data)=> {
console.info('rssi err ' + JSON.stringify(err));
console.info('rssi value' + JSON.stringify(data));
})
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### getRssiValue
getRssiValue(): Promise&lt;number&gt;
Obtains the RSSI of the remote BLE device. This API uses a promise to return the result. It can be used only after a connection is set up by calling [connect](#connect).
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| --------------------- | --------------------------------- |
| Promise&lt;number&gt; | Promise used to return the RSSI, in dBm.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
// promise
try {
let gattClient = ble.createGattClientDevice("XX:XX:XX:XX:XX:XX");
let rssi = gattClient.getRssiValue().then((data) => {
console.info('rssi' + JSON.stringify(data));
})
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### setBLEMtuSize
setBLEMtuSize(mtu: number): void
Sets the maximum transmission unit (MTU) that can be transmitted between the GATT client and its remote BLE device. This API can be used only after a connection is set up by calling [connect](#connect).
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | -------------- |
| mtu | number | Yes | MTU to set, which ranges from 22 to 512 bytes.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.setBLEMtuSize(128);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### setCharacteristicChangeNotification
setCharacteristicChangeNotification(characteristic: BLECharacteristic, enable: boolean, callback: AsyncCallback&lt;void&gt;): void
Sets the function of notifying the GATT client when the characteristic value of the remote BLE device changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | --------------------------------------- | ---- | ----------------------------- |
| characteristic | [BLECharacteristic](#blecharacteristic) | Yes | BLE characteristic to listen for. |
| enable | boolean | Yes | Whether to enable the notify function. The value **true** means to enable the notify function, and the value **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
// Create descriptors.
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.setCharacteristicChangeNotification(characteristic, false);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### setCharacteristicChangeNotification
setCharacteristicChangeNotification(characteristic: BLECharacteristic, enable: boolean): Promise&lt;void&gt;
Sets the function of notifying the GATT client when the characteristic value of the remote BLE device changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | --------------------------------------- | ---- | ----------------------------- |
| characteristic | [BLECharacteristic](#blecharacteristic) | Yes | BLE characteristic to listen for. |
| enable | boolean | Yes | Whether to enable the notify function. The value **true** means to enable the notify function, and the value **false** means the opposite.|
**Return value**
| Type | Description |
| ---------------------------------------- | -------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
// Create descriptors.
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.setCharacteristicChangeNotification(characteristic, false);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### setCharacteristicChangeIndication
setCharacteristicChangeIndication(characteristic: BLECharacteristic, enable: boolean, callback: AsyncCallback&lt;void&gt;): void
Sets the function of notifying the GATT client when the characteristic value of the remote BLE device changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | --------------------------------------- | ---- | ----------------------------- |
| characteristic | [BLECharacteristic](#blecharacteristic) | Yes | BLE characteristic to listen for. |
| enable | boolean | Yes | Whether to enable the notify function. The value **true** means to enable the notify function, and the value **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Return value**
| Type | Description |
| ---------------------------------------- | -------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
// Create descriptors.
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.setCharacteristicChangeIndication(characteristic, false);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### setCharacteristicChangeIndication
setCharacteristicChangeIndication(characteristic: BLECharacteristic, enable: boolean): Promise&lt;void&gt;
Sets the function of notifying the GATT client when the characteristic value of the remote BLE device changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | --------------------------------------- | ---- | ----------------------------- |
| characteristic | [BLECharacteristic](#blecharacteristic) | Yes | BLE characteristic to listen for. |
| enable | boolean | Yes | Whether to enable the notify function. The value **true** means to enable the notify function, and the value **false** means the opposite.|
**Return value**
| Type | Description |
| ---------------------------------------- | -------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
// Create descriptors.
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.setCharacteristicChangeIndication(characteristic, false);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### on('BLECharacteristicChange')
on(type: 'BLECharacteristicChange', callback: Callback&lt;BLECharacteristic&gt;): void
Subscribes to BLE characteristic changes. The client can receive a notification from the server only after the **setNotifyCharacteristicChanged** method is called.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **BLECharacteristicChange** indicates a characteristic value change event.|
| callback | Callback&lt;[BLECharacteristic](#blecharacteristic)&gt; | Yes | Callback invoked to return the characteristic value changes. |
**Example**
```js
function CharacteristicChange(CharacteristicChangeReq) {
let serviceUuid = CharacteristicChangeReq.serviceUuid;
let characteristicUuid = CharacteristicChangeReq.characteristicUuid;
let value = new Uint8Array(CharacteristicChangeReq.characteristicValue);
}
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.on('BLECharacteristicChange', CharacteristicChange);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### off('BLECharacteristicChange')
off(type: 'BLECharacteristicChange', callback?: Callback&lt;BLECharacteristic&gt;): void
Unsubscribes from BLE characteristic change events.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **BLECharacteristicChange** indicates a characteristic value change event.|
| callback | Callback&lt;[BLECharacteristic](#blecharacteristic)&gt; | No | Callback for the characteristic value change event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.off('BLECharacteristicChange');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### on('BLEConnectionStateChange')
on(type: 'BLEConnectionStateChange', callback: Callback&lt;BLEConnectionChangeState&gt;): void
Subscribes to BLE connection state changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **BLEConnectionStateChange** indicates a BLE connection state change event.|
| callback | Callback&lt;[BLEConnectionChangeState](#bleconnectionchangestate)&gt; | Yes | Callback invoked to return the BLE connection state. |
**Example**
```js
function ConnectStateChanged(state) {
console.log('bluetooth connect state changed');
let connectState = state.state;
}
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.on('BLEConnectionStateChange', ConnectStateChanged);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### off('BLEConnectionStateChange')
off(type: 'BLEConnectionStateChange', callback?: Callback&lt;BLEConnectionChangeState&gt;): void
Unsubscribes from BLE connection state changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **BLEConnectionStateChange** indicates a BLE connection state change event.|
| callback | Callback&lt;[BLEConnectionChangeState](#bleconnectionchangestate)&gt; | No | Callback for the BLE connection state change event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.off('BLEConnectionStateChange');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### on('BLEMtuChange')
on(type: 'BLEMtuChange', callback: Callback&lt;number&gt;): void
Subscribes to MTU status changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **BLEMtuChange**, which indicates a MTU status change event.|
| callback | Callback&lt;number&gt; | Yes | Callback invoked to return the MTU status, which can be connected or disconnected.|
**Example**
```js
try {
let gattClient = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
gattClient.on('BLEMtuChange', (mtu) => {
console.info('BLEMtuChange, mtu: ' + mtu);
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### off('BLEMtuChange')
off(type: 'BLEMtuChange', callback?: Callback&lt;number&gt;): void
Unsubscribes from MTU status changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **BLEMtuChange**, which indicates a MTU status change event.|
| callback | Callback&lt;number&gt; | No | Callback for MTU status changes. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
try {
let device = ble.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.off('BLEMtuChange');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## GattService
Defines the GATT service API parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| --------------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
| serviceUuid | string | Yes | Yes | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
| isPrimary | boolean | Yes | Yes | Whether the service is a primary service. The value **true** means a primary service. |
| characteristics | Array&lt;[BLECharacteristic](#blecharacteristic)&gt; | Yes | Yes | List of characteristics of the service. |
| includeServices | Array&lt;[GattService](#gattservice)&gt; | Yes | Yes | Services on which the service depends. |
## BLECharacteristic
Defines the characteristic API parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
| serviceUuid | string | Yes | Yes | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
| characteristicUuid | string | Yes | Yes | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| characteristicValue | ArrayBuffer | Yes | Yes | Binary value of the characteristic. |
| descriptors | Array&lt;[BLEDescriptor](#bledescriptor)&gt; | Yes | Yes | List of descriptors of the characteristic. |
| properties | [GattProperties](#gattproperties) | Yes | Yes | Properties of the characteristic. |
## BLEDescriptor
Defines the BLE descriptor.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------ | ----------- | ---- | ---- | ---------------------------------------- |
| serviceUuid | string | Yes | Yes | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
| characteristicUuid | string | Yes | Yes | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| descriptorUuid | string | Yes | Yes | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
| descriptorValue | ArrayBuffer | Yes | Yes | Binary value of the descriptor. |
## NotifyCharacteristic
Defines the parameters in the notifications sent when the server characteristic value changes.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------- | ----------- | ---- | ---- | ---------------------------------------- |
| serviceUuid | string | Yes | Yes | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
| characteristicUuid | string | Yes | Yes | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| characteristicValue | ArrayBuffer | Yes | Yes | Binary value of the characteristic. |
| confirm | boolean | Yes | Yes | Whether the notification needs to be confirmed by the remote end. For a notification, set it to **true**. In this case, the remote end must confirm the receipt of the notification. For an indication, set it to **false**. In this case, the remote end does not need to confirm the receipt of the notification.|
## CharacteristicReadRequest
Defines the parameters of the **CharacteristicReadReq** event received by the server.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
| deviceId | string | Yes | No | Address of the remote device that sends the **CharacteristicReadReq** event, for example, XX:XX:XX:XX:XX:XX.|
| transId | number | Yes | No | Transmission ID of the read request. The response returned by the server must use the same transmission ID. |
| offset | number | Yes | No | Position from which the characteristic value is read. For example, **k** means to read from the kth byte. The response returned by the server must use the same offset.|
| characteristicUuid | string | Yes | No | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## CharacteristicWriteRequest
Defines the parameters of the **CharacteristicWriteReq** event received by the server.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
| deviceId | string | Yes | No | Address of the remote device that sends the **CharacteristicWriteReq** event, for example, XX:XX:XX:XX:XX:XX.|
| transId | number | Yes | No | Transmission ID of the write request. The response returned by the server must use the same transmission ID. |
| offset | number | Yes | No | Start position for writing the characteristic value. For example, **k** means to write from the kth byte. The response returned by the server must use the same offset.|
| isPrepared | boolean | Yes | No | Whether the write request is executed immediately.|
| needRsp | boolean | Yes | No | Whether to send a response to the GATT client.|
| value | ArrayBuffer | Yes | No | Binary value of the descriptor to write.|
| characteristicUuid | string | Yes | No | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## DescriptorReadRequest
Defines the parameters of the **DescriptorReadReq** event received by the server.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
| deviceId | string | Yes | No | Address of the remote device that sends a **DescriptorReadReq** event, for example, XX:XX:XX:XX:XX:XX.|
| transId | number | Yes | No | Transmission ID of the read request. The response returned by the server must use the same transmission ID. |
| offset | number | Yes | No | Position from which the descriptor is read. For example, **k** means to read from the kth byte. The response returned by the server must use the same offset.|
| descriptorUuid | string | Yes | No | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
| characteristicUuid | string | Yes | No | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## DescriptorWriteRequest
Defines the parameters of the **DescriptorWriteReq** event received by the server.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------ | ----------- | ---- | ---- | ---------------------------------------- |
| deviceId | string | Yes | No | Address of the remote device that sends a **DescriptorWriteReq** event, for example, XX:XX:XX:XX:XX:XX.|
| transId | number | Yes | No | Transmission ID of the write request. The response returned by the server must use the same transmission ID. |
| offset | number | Yes | No | Start position for writing the descriptor. For example, **k** means to write from the kth byte. The response returned by the server must use the same offset.|
| isPrepared | boolean | Yes | No | Whether the write request is executed immediately. |
| needRsp | boolean | Yes | No | Whether to send a response to the GATT client. |
| value | ArrayBuffer | Yes | No | Binary value of the descriptor to write. |
| descriptorUuid | string | Yes | No | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
| characteristicUuid | string | Yes | No | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## ServerResponse
Defines the parameters of the server's response to the GATT client's read/write request.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| -------- | ----------- | ---- | ---- | -------------------------------------- |
| deviceId | string | Yes | No | Address of the remote device, for example, XX:XX:XX:XX:XX:XX. |
| transId | number | Yes | No | Transmission ID of the request. The value must be the same as the ID carried in the read/write request received. |
| status | number | Yes | No | Response state. Set this parameter to **0**, which indicates a normal response. |
| offset | number | Yes | No | Start read/write position. The value must be the same as the offset carried in the read/write request.|
| value | ArrayBuffer | Yes | No | Binary data in the response. |
## BLEConnectionChangeState
Defines the parameters of **BLEConnectChangedState**.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable| Writable| Description |
| -------- | ------------------------------------------------- | ---- | ---- | --------------------------------------------- |
| deviceId | string | Yes | No | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
| state | [ProfileConnectionState](js-apis-bluetooth-constant.md#profileconnectionstate) | Yes | Yes | BLE connection state. |
## ScanResult
Defines the scan result.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| -------- | ----------- | ---- | ---- | ---------------------------------- |
| deviceId | string | Yes | No | Address of the scanned device, for example, XX:XX:XX:XX:XX:XX.|
| rssi | number | Yes | No | RSSI of the device. |
| data | ArrayBuffer | Yes | No | Advertisement packets sent by the device. |
| deviceName | string | Yes | No | Name of the device detected. |
| connectable | boolean | Yes | No | Whether the discovered device is connectable. |
## AdvertiseSetting
Defines the BLE advertising parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ----------- | ------- | ---- | ---- | ---------------------------------------- |
| interval | number | Yes | Yes | Interval for BLE advertising. The minimum value is **32** slots (20 ms). The maximum value is **16384** slots. The default value is **1600** slots (1s).|
| txPower | number | Yes | Yes | Transmit power, in dBm. The value range is -127 to 1. The default value is **-7**. |
| connectable | boolean | Yes | Yes | Whether the advertisement is connectable. The default value is **true**. |
## AdvertiseData
Defines the content of a BLE advertisement packet.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| --------------- | ---------------------------------------- | ---- | ---- | --------------------------- |
| serviceUuids | Array&lt;string&gt; | Yes | Yes | List of service UUIDs to broadcast.|
| manufactureData | Array&lt;[ManufactureData](#manufacturedata)&gt; | Yes | Yes | List of manufacturers to broadcast. |
| serviceData | Array&lt;[ServiceData](#servicedata)&gt; | Yes | Yes | List of service data to broadcast. |
| includeDeviceName | boolean | Yes | Yes | Whether the device name is contained. This parameter is optional. |
## ManufactureData
Defines the content of a BLE advertisement packet.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ---------------- | ------------------- | ---- | ---- | ------------------ |
| manufactureId | number | Yes | Yes | Manufacturer ID allocated by the Bluetooth SIG.|
| manufactureValue | ArrayBuffer | Yes | Yes | Manufacturer data. |
## ServiceData
Defines the service data contained in an advertisement packet.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------ | ----------- | ---- | ---- | ---------- |
| serviceUuid | string | Yes | Yes | Service UUID.|
| serviceValue | ArrayBuffer | Yes | Yes | Service data. |
## ScanFilter
Defines the scan filter parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable| Writable| Description |
| ---------------------------------------- | ----------- | ---- | ---- | ------------------------------------------------------------ |
| deviceId | string | Yes | Yes | Address of the BLE device to filter, for example, XX:XX:XX:XX:XX:XX. |
| name | string | Yes | Yes | Name of the BLE device to filter. |
| serviceUuid | string | Yes | Yes | Service UUID of the device to filter, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
| serviceUuidMask | string | Yes | Yes | Service UUID mask of the device to filter, for example, **FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF**.|
| serviceSolicitationUuid | string | Yes | Yes | Service solicitation UUID of the device to filter, for example, **00001888-0000-1000-8000-00805F9B34FB**.|
| serviceSolicitationUuidMask | string | Yes | Yes | Service solicitation UUID mask of the device to filter, for example, **FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF**.|
| serviceData | ArrayBuffer | Yes | Yes | Service data of the device to filter, for example, **[0x90, 0x00, 0xF1, 0xF2]**.|
| serviceDataMask | ArrayBuffer | Yes | Yes | Service data mask of the device to filter, for example, **[0xFF,0xFF,0xFF,0xFF]**.|
| manufactureId | number | Yes | Yes | Manufacturer ID of the device to filter, for example, **0x0006**. |
| manufactureData | ArrayBuffer | Yes | Yes | Manufacturer data of the device to filter, for example, **[0x1F,0x2F,0x3F]**.|
| manufactureDataMask | ArrayBuffer | Yes | Yes | Manufacturer data mask of the device to filter, for example, **[0xFF, 0xFF, 0xFF]**.|
## ScanOptions
Defines the scan configuration parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| --------- | ----------------------- | ---- | ---- | -------------------------------------- |
| interval | number | Yes | Yes | Delay in reporting the scan result. The default value is **0**. |
| dutyMode | [ScanDuty](#scanduty) | Yes | Yes | Scan duty. The default value is SCAN_MODE_LOW_POWER. |
| matchMode | [MatchMode](#matchmode) | Yes | Yes | Hardware filtering match mode. The default value is **MATCH_MODE_AGGRESSIVE**.|
## GattProperties<a name="GattProperties"></a>
Defines the properties of a GATT characteristic.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Mandatory | Description |
| -------- | ------ |---- | ----------- |
| write | boolean | Yes | Permits writes of the characteristic value (with a response).|
| writeNoResponse | boolean | Yes | Permits writes of the characteristic value (without a response).|
| read | boolean | Yes | Permits reads of the characteristic value.|
| notify | boolean | Yes | Permits notifications of the characteristic value.|
| indicate | boolean | Yes | Permits notifications of the characteristic value without acknowledgement.|
## GattWriteType<a name="GattWriteType"></a>
Enumerates the GATT write types.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ------------------------------------| ------ | --------------- |
| WRITE | 1 | Write a characteristic value with a response from the peer device. |
| WRITE_NO_RESPONSE | 2 | Write characteristic value without a response from the peer device. |
## ScanDuty
Enumerates the scan duties.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| --------------------- | ---- | ------------ |
| SCAN_MODE_LOW_POWER | 0 | Low-power mode, which is the default value.|
| SCAN_MODE_BALANCED | 1 | Balanced mode. |
| SCAN_MODE_LOW_LATENCY | 2 | Low-latency mode. |
## MatchMode
Enumerates the hardware match modes of BLE scan filters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| --------------------- | ---- | ---------------------------------------- |
| MATCH_MODE_AGGRESSIVE | 1 | Hardware reports the scan result with a lower threshold of signal strength and few number of matches in a duration. This is the default value.|
| MATCH_MODE_STICKY | 2 | Hardware reports the scan result with a higher threshold of signal strength and sightings. |
# @ohos.bluetooth.connection (Bluetooth connection Module)
The **connection** module provides APIs for operating and managing Bluetooth.
> **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.
## Modules to Import
```js
import connection from '@ohos.bluetooth.connection';
```
## connection.pairDevice<a name="pairDevice"></a>
pairDevice(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
Pairs a Bluetooth device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the pairing is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
// The address can be scanned.
connection.pairDevice('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.pairDevice<a name="pairDevice"></a>
pairDevice(deviceId: string): Promise&lt;void&gt;
Pairs a Bluetooth device. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.|
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
// The address can be scanned.
connection.pairDevice('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.pairCredibleDevice
pairCredibleDevice(deviceId: string, transport: BluetoothTransport, callback: AsyncCallback&lt;void&gt;): void
Pairs a trusted device whose address is obtained in a non-Bluetooth scan mode (such as using NFC). This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.|
| transport | [BluetoothTransport](#bluetoothtransport) | Yes | Device type, for example, a classic Bluetooth device or a Bluetooth low energy (BLE) device.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
connection.pairCredibleDevice('68:13:24:79:4C:8C', 1, err => {
if (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
return;
}
console.info('pairCredibleDevice, err: ' + JSON.stringify(err));
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.pairCredibleDevice
pairCredibleDevice(deviceId: string, transport: BluetoothTransport): Promise&lt;void&gt;
Pairs a trusted device whose address is obtained in a non-Bluetooth scan mode (such as using NFC). This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.|
| transport | [BluetoothTransport](#bluetoothtransport) | Yes | Device type, for example, a classic Bluetooth device or a BLE device.|
**Return value**
| Type | Description |
| ------------------------------------------------- | ------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
connection.pairCredibleDevice('68:13:24:79:4C:8C', 0).then(() => {
console.info('PairCredibleDevice');
}, err => {
console.error('PairCredibleDevice:errCode' + err.code + ', errMessage: ' + err.message);
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.cancelPairedDevice<a name="cancelPairedDevice"></a>
cancelPairedDevice(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
Cancels a paired device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------------------------------- |
| deviceId | string | Yes | Address of the device to cancel, for example, XX:XX:XX:XX:XX:XX.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
connection.cancelPairedDevice('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.cancelPairedDevice<a name="cancelPairedDevice"></a>
cancelPairedDevice(deviceId: string): Promise&lt;void&gt;
Cancels a paired device. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------------------------------- |
| deviceId | string | Yes | Address of the device to cancel, for example, XX:XX:XX:XX:XX:XX.|
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
connection.cancelPairedDevice('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.cancelPairingDevice<a name="cancelPairingDevice"></a>
cancelPairingDevice(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
Cancels the pairing of a device. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------------------------------- |
| deviceId | string | Yes | Address of the device to cancel, for example, XX:XX:XX:XX:XX:XX.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
connection.cancelPairingDevice('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.cancelPairingDevice<a name="cancelPairingDevice"></a>
cancelPairingDevice(deviceId: string): Promise&lt;void&gt;
Cancels the pairing of a device. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------------------------------- |
| deviceId | string | Yes | Address of the device to cancel, for example, XX:XX:XX:XX:XX:XX.|
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
connection.cancelPairingDevice('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.getRemoteDeviceName<a name="getRemoteDeviceName"></a>
getRemoteDeviceName(deviceId: string): string
Obtains the name of a remote Bluetooth device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | --------------------------------- |
| deviceId | string | Yes | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
**Return value**
| Type | Description |
| ------ | ------------- |
| string | Device name (a string) obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let remoteDeviceName = connection.getRemoteDeviceName('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.getRemoteDeviceClass<a name="getRemoteDeviceClass"></a>
getRemoteDeviceClass(deviceId: string): DeviceClass
Obtains the class of a remote Bluetooth device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | --------------------------------- |
| deviceId | string | Yes | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
**Return value**
| Type | Description |
| --------------------------- | -------- |
| [DeviceClass](#deviceclass) | Class of the remote device obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let remoteDeviceClass = connection.getRemoteDeviceClass('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.getLocalName<a name="getLocalName"></a>
getLocalName(): string
Obtains the name of the local Bluetooth device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ------ | --------- |
| string | Name of the local Bluetooth device obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
try {
let localName = connection.getLocalName();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.getPairedDevices<a name="getPairedDevices"></a>
getPairedDevices(): Array&lt;string&gt;
Obtains the paired devices.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Array&lt;string&gt; | Addresses of the paired Bluetooth devices obtained. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let devices = connection.getPairedDevices();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.getProfileConnectionState<a name="getProfileConnectionState"></a>
getProfileConnectionState(profileId?: ProfileId): ProfileConnectionState
Obtains the connection state of the specified profile.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | --------- | ---- | ------------------------------------- |
| ProfileId | [profileId](js-apis-bluetooth-constant.md#profileid) | No | ID of the target profile, for example, **PROFILE_A2DP_SOURCE**.|
**Return value**
| Type | Description |
| ------------------------------------------------- | ------------------- |
| [ProfileConnectionState](js-apis-bluetooth-constant.md#profileconnectionstate) | Profile connection state obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
import constant from '@ohos.bluetooth.constant';
try {
let result = connection.getProfileConnectionState(constant.ProfileId.PROFILE_A2DP_SOURCE);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.setDevicePairingConfirmation<a name="setDevicePairingConfirmation"></a>
setDevicePairingConfirmation(deviceId: string, accept: boolean): void
Sets the device pairing confirmation.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------- | ---- | -------------------------------- |
| deviceId | string | Yes | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
| accept | boolean | Yes | Whether to accept the pairing request. The value **true** means to accept the pairing request, and the value **false** means the opposite. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
// Subscribe to the pinRequired event and configure the pairing confirmation after receiving a pairing request from the remote device.
function onReceivePinRequiredEvent(data) { // data is the input parameter for the pairing request.
console.info('pin required = '+ JSON.stringify(data));
connection.setDevicePairingConfirmation(data.deviceId, true);
}
connection.on('pinRequired', onReceivePinRequiredEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.setDevicePinCode<a name="setDevicePinCode"></a>
setDevicePinCode(deviceId: string, code: string, callback: AsyncCallback&lt;void&gt;): void
Sets the PIN for the device when [PinType](#pintype) is **PIN_TYPE_ENTER_PIN_CODE** or **PIN_TYPE_PIN_16_DIGITS**. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------- | ---- | -------------------------------- |
| deviceId | string | Yes | MAC address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
| code | string | Yes | PIN to set. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
//callback
try {
connection.setDevicePinCode('11:22:33:44:55:66', '12345', (err, data) => {
console.info('setDevicePinCode,device name err:' + JSON.stringify(err) + ',device name:' + JSON.stringify(data));
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.setDevicePinCode<a name="setDevicePinCode-1"></a>
setDevicePinCode(deviceId: string, code: string): Promise&lt;void&gt;
Sets the PIN for the device when [PinType](#pintype) is **PIN_TYPE_ENTER_PIN_CODE** or **PIN_TYPE_PIN_16_DIGITS**. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------- | ---- | -------------------------------- |
| deviceId | string | Yes | MAC address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
| code | string | Yes | PIN to set. |
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
//promise
try {
connection.setDevicePinCode('11:22:33:44:55:66', '12345').then(() => {
console.info('setDevicePinCode');
}, error => {
console.info('setDevicePinCode: errCode:' + error.code + ',errMessage' + error.message);
})
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.setLocalName<a name="setLocalName"></a>
setLocalName(name: string): void
Sets the name of the local Bluetooth device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | --------------------- |
| name | string | Yes | Bluetooth device name to set. It cannot exceed 248 bytes.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
connection.setLocalName('device_name');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.setBluetoothScanMode<a name="setBluetoothScanMode"></a>
setBluetoothScanMode(mode: ScanMode, duration: number): void
Sets the Bluetooth scan mode so that the device can be discovered by a remote device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------- | ---- | ---------------------------- |
| mode | [ScanMode](#scanmode) | Yes | Bluetooth scan mode to set. |
| duration | number | Yes | Duration (in ms) in which the device can be discovered. The value **0** indicates unlimited time.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
// The device can be discovered and connected only when the discoverable and connectable mode is used.
connection.setBluetoothScanMode(connection.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 100);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.getBluetoothScanMode<a name="getBluetoothScanMode"></a>
getBluetoothScanMode(): ScanMode
Obtains the Bluetooth scan mode.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| --------------------- | ------- |
| [ScanMode](#scanmode) | Bluetooth scan mode obtained. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let scanMode = connection.getBluetoothScanMode();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.startBluetoothDiscovery<a name="startBluetoothDiscovery"></a>
startBluetoothDiscovery(): void
Starts discovery of Bluetooth devices.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
let deviceId;
function onReceiveEvent(data) {
deviceId = data;
}
try {
connection.on('bluetoothDeviceFind', onReceiveEvent);
connection.startBluetoothDiscovery();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.stopBluetoothDiscovery<a name="stopBluetoothDiscovery"></a>
stopBluetoothDiscovery(): void
Stops discovery of Bluetooth devices.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
connection.stopBluetoothDiscovery();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.getLocalProfileUuids<a name="getLocalProfileUuids"></a>
getLocalProfileUuids(callback: AsyncCallback&lt;Array&lt;ProfileUuids&gt;&gt;): void
Obtains the profile UUIDs of the local device. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[ProfileUuids](js-apis-bluetooth-constant.md#profileuuids)&gt;&gt; | Yes | Callback invoked to return the profile UUIDs obtained. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
connection.getLocalProfileUuids('XX:XX:XX:XX:XX:XX', (err, data) => {
console.info('getLocalProfileUuids, err: ' + JSON.stringify(err) + ', data: ' + JSON.stringify(data));
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.getLocalProfileUuids<a name="getLocalProfileUuids"></a>
getLocalProfileUuids(): Promise&lt;Array&lt;ProfileUuids&gt;&gt;
Obtains the profile UUIDs of the local device. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;Array&lt;[ProfileUuids](js-apis-bluetooth-constant.md#profileuuids)&gt;&gt; | Promise used to return the profile UUIDs obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
connection.getLocalProfileUuids('XX:XX:XX:XX:XX:XX').then(() => {
console.info('getLocalProfileUuids');
}, err => {
console.error('getLocalProfileUuids: errCode' + err.code + ', errMessage: ' + err.message);
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.getRemoteProfileUuids<a name="getRemoteProfileUuids"></a>
getRemoteProfileUuids(deviceId: string, callback: AsyncCallback&lt;Array&lt;ProfileUuids&gt;&gt;): void
Obtains the profile UUIDs of a remote Bluetooth device. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.|
| callback | AsyncCallback&lt;Array&lt;[ProfileUuids](js-apis-bluetooth-constant.md#profileuuids)&gt;&gt; | Yes | Callback invoked to return the profile UUIDs obtained. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
connection.getRemoteProfileUuids('XX:XX:XX:XX:XX:XX', (err, data) => {
console.info('getRemoteProfileUuids, err: ' + JSON.stringify(err) + ', data: ' + JSON.stringify(data));
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.getRemoteProfileUuids<a name="getRemoteProfileUuids"></a>
getRemoteProfileUuids(deviceId: string): Promise&lt;Array&lt;ProfileUuids&gt;&gt;
Obtains the profile UUIDs of a remote Bluetooth device. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.|
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;Array&lt;[ProfileUuids](js-apis-bluetooth-constant.md#profileuuids)&gt;&gt; | Promise used to return the profile UUIDs obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
connection.getRemoteProfileUuids('XX:XX:XX:XX:XX:XX').then(() => {
console.info('getRemoteProfileUuids');
}, err => {
console.error('getRemoteProfileUuids: errCode' + err.code + ', errMessage: ' + err.message);
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.on('bluetoothDeviceFind')
on(type: 'bluetoothDeviceFind', callback: Callback&lt;Array&lt;string&gt;&gt;): void
Subscribes to the discovery of a Bluetooth device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------- | ---- | -------------------------------------- |
| type | string | Yes | Event type. The value is **bluetoothDeviceFind**, which indicates an event of discovering a Bluetooth device.|
| callback | Callback&lt;Array&lt;string&gt;&gt; | Yes | Callback invoked to return the discovered devices. You need to implement this callback. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) { // data is a set of Bluetooth device addresses.
console.info('bluetooth device find = '+ JSON.stringify(data));
}
try {
connection.on('bluetoothDeviceFind', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.off('bluetoothDeviceFind')
off(type: 'bluetoothDeviceFind', callback?: Callback&lt;Array&lt;string&gt;&gt;): void
Unsubscribes from the discovery of a Bluetooth device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **bluetoothDeviceFind**, which indicates an event of discovering a Bluetooth device. |
| callback | Callback&lt;Array&lt;string&gt;&gt; | No | Callback for the **bluetoothDeviceFind** event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bluetooth device find = '+ JSON.stringify(data));
}
try {
connection.on('bluetoothDeviceFind', onReceiveEvent);
connection.off('bluetoothDeviceFind', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.on('bondStateChange')
on(type: 'bondStateChange', callback: Callback&lt;BondStateParam&gt;): void
Subscribes to Bluetooth pairing state changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
| type | string | Yes | Event type. The value is **bondStateChange**, which indicates a Bluetooth pairing state change event.|
| callback | Callback&lt;[BondStateParam](#BondStateParam)&gt; | Yes | Callback invoked to return the pairing state. You need to implement this callback. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) { // data, as the input parameter of the callback, indicates the pairing state.
console.info('pair state = '+ JSON.stringify(data));
}
try {
connection.on('bondStateChange', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.off('bondStateChange')
off(type: 'bondStateChange', callback?: Callback&lt;BondStateParam&gt;): void
Unsubscribes from Bluetooth pairing state changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **bondStateChange**, which indicates a Bluetooth pairing state change event. |
| callback | Callback&lt;[BondStateParam](#BondStateParam)&gt; | No | Callback for the change of the Bluetooth pairing state. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bond state = '+ JSON.stringify(data));
}
try {
connection.on('bondStateChange', onReceiveEvent);
connection.off('bondStateChange', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.on('pinRequired')
on(type: 'pinRequired', callback: Callback&lt;PinRequiredParam&gt;): void
Subscribes to the pairing request events of the remote Bluetooth device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | -------------------------------- |
| type | string | Yes | Event type. The value **pinRequired** indicates a pairing request event. |
| callback | Callback&lt;[PinRequiredParam](#pinrequiredparam)&gt; | Yes | Callback invoked to return the pairing request. You need to implement this callback.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) { // data is the pairing request parameter.
console.info('pin required = '+ JSON.stringify(data));
}
try {
connection.on('pinRequired', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## connection.off('pinRequired')
off(type: 'pinRequired', callback?: Callback&lt;PinRequiredParam&gt;): void
Unsubscribes from the pairing request events of the remote Bluetooth device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **pinRequired** indicates a pairing request event. |
| callback | Callback&lt;[PinRequiredParam](#pinrequiredparam)&gt; | No | Callback for the Bluetooth pairing request event. The input parameter is the pairing request parameter. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('pin required = '+ JSON.stringify(data));
}
try {
connection.on('pinRequired', onReceiveEvent);
connection.off('pinRequired', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## BondStateParam<a name="BondStateParam"></a>
Represents the pairing state parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| -------- | ------ | ---- | ---- | ----------- |
| deviceId | string | Yes | No | ID of the device to pair.|
| state | BondState | Yes | No | State of the device.|
## PinRequiredParam<a name="PinRequiredParam"></a>
Represents the pairing request parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| -------- | ------ | ---- | ---- | ----------- |
| deviceId | string | Yes | No | ID of the device to pair.|
| pinCode | string | Yes | No | Key for the device pairing. |
| pinType | [PinType](#pintype) | Yes | No | Type of the device to pair.<br>This is a system API. |
## DeviceClass<a name="DeviceClass"></a>
Represents the class of a Bluetooth device.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| --------------- | ----------------------------------- | ---- | ---- | ---------------- |
| majorClass | [MajorClass](js-apis-bluetooth-constant.md#majorclass) | Yes | No | Major class of the Bluetooth device. |
| majorMinorClass | [MajorMinorClass](js-apis-bluetooth-constant.md#majorminorclass) | Yes | No | Major and minor classes of the Bluetooth device.|
| classOfDevice | number | Yes | No | Class of the device. |
## BluetoothTransport<a name="BluetoothTransport"></a>
Enumerates the device types.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| -------------------------------- | ------ | --------------- |
| TRANSPORT_BR_EDR | 0 | Classic Bluetooth (BR/EDR) device, which is the default value. |
| TRANSPORT_LE | 1 | BLE device. |
## ScanMode<a name="ScanMode"></a>
Enumerates the scan modes.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ---------------------------------------- | ---- | --------------- |
| SCAN_MODE_NONE | 0 | No scan mode. |
| SCAN_MODE_CONNECTABLE | 1 | Connectable mode. |
| SCAN_MODE_GENERAL_DISCOVERABLE | 2 | General discoverable mode. |
| SCAN_MODE_LIMITED_DISCOVERABLE | 3 | Limited discoverable mode. |
| SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE | 4 | General connectable and discoverable mode.|
| SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE | 5 | Limited connectable and discoverable mode.|
## BondState<a name="BondState"></a>
Enumerates the pairing states.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ------------------ | ---- | ------ |
| BOND_STATE_INVALID | 0 | Invalid pairing.|
| BOND_STATE_BONDING | 1 | Pairing. |
| BOND_STATE_BONDED | 2 | Paired. |
## PinType<a name="PinType"></a>
Enumerates the Bluetooth pairing types.
**System API**: This is a system API.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| -------------------------------- | ------ | --------------- |
| PIN_TYPE_ENTER_PIN_CODE | 0 | The user needs to enter the PIN displayed on the peer device.<br>This is a system API.|
| PIN_TYPE_ENTER_PASSKEY | 1 | The user needs to enter the PASSKEY displayed on the peer device.<br>This is a system API. |
| PIN_TYPE_CONFIRM_PASSKEY | 2 | The user needs to confirm the PASSKEY displayed on the local device.<br>This is a system API. |
| PIN_TYPE_NO_PASSKEY_CONSENT | 3 | There is no PASSKEY, and the user needs to accept or reject the pairing request.<br>This is a system API. |
| PIN_TYPE_NOTIFY_PASSKEY | 4 | The user needs to enter the PASSKEY displayed on the local device on the peer device.<br>This is a system API. |
| PIN_TYPE_DISPLAY_PIN_CODE | 5 | The user needs to enter the PIN displayed on the peer device for Bluetooth 2.0 devices.<br>This is a system API. |
| PIN_TYPE_OOB_CONSENT | 6 | The user needs to accept or reject the out of band (OOB) pairing request.<br>This is a system API. |
| PIN_TYPE_PIN_16_DIGITS | 7 | The user needs to enter the 16-digit PIN displayed on the peer device.<br>This is a system API. |
# @ohos.bluetooth.constant (Bluetooth constant Module)
The **constant** module provides definitions of the constants used in Bluetooth.
> **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.
## Modules to Import
```js
import constant from '@ohos.bluetooth.constant';
```
## ProfileId<a name="ProfileId"></a>
Enumerates profiles.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| -------------------------------- | ------ | --------------- |
| PROFILE_A2DP_SOURCE | 1 | Advanced Audio Distribution Profile (A2DP).|
| PROFILE_HANDSFREE_AUDIO_GATEWAY | 4 | Hands-Free Profile (HFP). |
| PROFILE_HID_HOST | 6 | Human Interface Device (HID) profile. |
| PROFILE_PAN_NETWORK | 7 | Bluetooth personal area network (PAN) profile. |
## ProfileUuids<a name="ProfileUuids"></a>
Enumerates profile UUIDs.
**System API**: This is a system API.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ------------------------------------| ------ | --------------- |
| PROFILE_UUID_HFP_AG | '0000111F-0000-1000-8000-00805F9B34FB' | UUID of the HFPAG Profile.<br>This is a system API.|
| PROFILE_UUID_HFP_HF | '0000111E-0000-1000-8000-00805F9B34FB' | UUID of the HFPHF Profile.<br>This is a system API. |
| PROFILE_UUID_HSP_AG | '00001112-0000-1000-8000-00805F9B34FB' | UUID of the HSPAG Profile.<br>This is a system API. |
| PROFILE_UUID_HSP_HS | '00001108-0000-1000-8000-00805F9B34FB' | UUID of the HSPHS Profile.<br>This is a system API. |
| PROFILE_UUID_A2DP_SRC | '0000110A-0000-1000-8000-00805F9B34FB' | Indicates the UID of the A2DPSRC Profile.<br>This is a system API. |
| PROFILE_UUID_A2DP_SINK | '0000110B-0000-1000-8000-00805F9B34FB' | UUID of the A2DPSINK Profile.<br>This is a system API. |
| PROFILE_UUID_AVRCP_CT | '0000110E-0000-1000-8000-00805F9B34FB' | UUID of the AVRCPCT Profile.<br>This is a system API. |
| PROFILE_UUID_AVRCP_TG | '0000110C-0000-1000-8000-00805F9B34FB' | UUID of the AVRCPTG Profile.<br>This is a system API. |
| PROFILE_UUID_HID | '00001124-0000-1000-8000-00805F9B34FB' | UUID of the HID Profile.<br>This is a system API. |
| PROFILE_UUID_HOGP | '00001812-0000-1000-8000-00805F9B34FB' | UUID of the HOGP Profile.<br>This is a system API. |
## ProfileConnectionState
Enumerates the profile connection states.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ------------------- | ---- | -------------- |
| STATE_DISCONNECTED | 0 | Disconnected. |
| STATE_CONNECTING | 1 | Connecting.|
| STATE_CONNECTED | 2 | Connected. |
| STATE_DISCONNECTING | 3 | Disconnecting.|
## MajorClass<a name="MajorClass"></a>
Enumerates the major classes of Bluetooth devices.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ------------------- | ------ | ---------- |
| MAJOR_MISC | 0x0000 | Miscellaneous device. |
| MAJOR_COMPUTER | 0x0100 | Computer. |
| MAJOR_PHONE | 0x0200 | Mobile phone. |
| MAJOR_NETWORKING | 0x0300 | Network device. |
| MAJOR_AUDIO_VIDEO | 0x0400 | Audio or video device.|
| MAJOR_PERIPHERAL | 0x0500 | Peripheral device. |
| MAJOR_IMAGING | 0x0600 | Imaging device. |
| MAJOR_WEARABLE | 0x0700 | Wearable device. |
| MAJOR_TOY | 0x0800 | Toy. |
| MAJOR_HEALTH | 0x0900 | Health device. |
| MAJOR_UNCATEGORIZED | 0x1F00 | Unclassified device. |
## MajorMinorClass<a name="MajorMinorClass"></a>
Enumerates the major and minor classes of Bluetooth devices.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ---------------------------------------- | ------ | --------------- |
| COMPUTER_UNCATEGORIZED | 0x0100 | Unclassified computer. |
| COMPUTER_DESKTOP | 0x0104 | Desktop computer. |
| COMPUTER_SERVER | 0x0108 | Server. |
| COMPUTER_LAPTOP | 0x010C | Laptop. |
| COMPUTER_HANDHELD_PC_PDA | 0x0110 | Hand-held computer. |
| COMPUTER_PALM_SIZE_PC_PDA | 0x0114 | Palmtop computer. |
| COMPUTER_WEARABLE | 0x0118 | Wearable computer. |
| COMPUTER_TABLET | 0x011C | Tablet. |
| PHONE_UNCATEGORIZED | 0x0200 | Unclassified mobile phone. |
| PHONE_CELLULAR | 0x0204 | Portable phone. |
| PHONE_CORDLESS | 0x0208 | Cordless phone. |
| PHONE_SMART | 0x020C | Smartphone. |
| PHONE_MODEM_OR_GATEWAY | 0x0210 | Modem or gateway phone.|
| PHONE_ISDN | 0x0214 | ISDN phone. |
| NETWORK_FULLY_AVAILABLE | 0x0300 | Device with network fully available. |
| NETWORK_1_TO_17_UTILIZED | 0x0320 | Device used on network 1 to 17. |
| NETWORK_17_TO_33_UTILIZED | 0x0340 | Device used on network 17 to 33. |
| NETWORK_33_TO_50_UTILIZED | 0x0360 | Device used on network 33 to 50. |
| NETWORK_60_TO_67_UTILIZED | 0x0380 | Device used on network 60 to 67. |
| NETWORK_67_TO_83_UTILIZED | 0x03A0 | Device used on network 67 to 83. |
| NETWORK_83_TO_99_UTILIZED | 0x03C0 | Device used on network 83 to 99. |
| NETWORK_NO_SERVICE | 0x03E0 | Device without network service |
| AUDIO_VIDEO_UNCATEGORIZED | 0x0400 | Unclassified audio or video device. |
| AUDIO_VIDEO_WEARABLE_HEADSET | 0x0404 | Wearable audio or video headset. |
| AUDIO_VIDEO_HANDSFREE | 0x0408 | Hands-free audio or video device. |
| AUDIO_VIDEO_MICROPHONE | 0x0410 | Audio or video microphone. |
| AUDIO_VIDEO_LOUDSPEAKER | 0x0414 | Audio or video loudspeaker. |
| AUDIO_VIDEO_HEADPHONES | 0x0418 | Audio or video headphones. |
| AUDIO_VIDEO_PORTABLE_AUDIO | 0x041C | Portable audio or video device. |
| AUDIO_VIDEO_CAR_AUDIO | 0x0420 | In-vehicle audio or video device. |
| AUDIO_VIDEO_SET_TOP_BOX | 0x0424 | Audio or video STB device. |
| AUDIO_VIDEO_HIFI_AUDIO | 0x0428 | High-fidelity speaker device. |
| AUDIO_VIDEO_VCR | 0x042C | Video cassette recording (VCR) device. |
| AUDIO_VIDEO_VIDEO_CAMERA | 0x0430 | Camera. |
| AUDIO_VIDEO_CAMCORDER | 0x0434 | Camcorder |
| AUDIO_VIDEO_VIDEO_MONITOR | 0x0438 | Audio or video monitor. |
| AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER | 0x043C | Video display or loudspeaker. |
| AUDIO_VIDEO_VIDEO_CONFERENCING | 0x0440 | Video conferencing device. |
| AUDIO_VIDEO_VIDEO_GAMING_TOY | 0x0448 | Audio or video gaming toy. |
| PERIPHERAL_NON_KEYBOARD_NON_POINTING | 0x0500 | Non-keyboard or non-pointing peripheral device. |
| PERIPHERAL_KEYBOARD | 0x0540 | Keyboard device. |
| PERIPHERAL_POINTING_DEVICE | 0x0580 | Pointing peripheral device. |
| PERIPHERAL_KEYBOARD_POINTING | 0x05C0 | Keyboard pointing device. |
| PERIPHERAL_UNCATEGORIZED | 0x0500 | Unclassified peripheral device. |
| PERIPHERAL_JOYSTICK | 0x0504 | Peripheral joystick. |
| PERIPHERAL_GAMEPAD | 0x0508 | Peripheral game pad |
| PERIPHERAL_REMOTE_CONTROL | 0x05C0 | Peripheral remote control device |
| PERIPHERAL_SENSING_DEVICE | 0x0510 | Peripheral sensing device. |
| PERIPHERAL_DIGITIZER_TABLET | 0x0514 | Peripheral digitizer tablet.|
| PERIPHERAL_CARD_READER | 0x0518 | Peripheral card reader. |
| PERIPHERAL_DIGITAL_PEN | 0x051C | Peripheral digital pen. |
| PERIPHERAL_SCANNER_RFID | 0x0520 | Peripheral RFID scanner. |
| PERIPHERAL_GESTURAL_INPUT | 0x0522 | Gesture input device. |
| IMAGING_UNCATEGORIZED | 0x0600 | Unclassified imaging device. |
| IMAGING_DISPLAY | 0x0610 | Imaging display device. |
| IMAGING_CAMERA | 0x0620 | Imaging camera device. |
| IMAGING_SCANNER | 0x0640 | Imaging scanner. |
| IMAGING_PRINTER | 0x0680 | Imaging printer. |
| WEARABLE_UNCATEGORIZED | 0x0700 | Unclassified wearable device. |
| WEARABLE_WRIST_WATCH | 0x0704 | Smart watch. |
| WEARABLE_PAGER | 0x0708 | Wearable pager. |
| WEARABLE_JACKET | 0x070C | Smart jacket. |
| WEARABLE_HELMET | 0x0710 | Wearable helmet. |
| WEARABLE_GLASSES | 0x0714 | Wearable glasses. |
| TOY_UNCATEGORIZED | 0x0800 | Unclassified toy. |
| TOY_ROBOT | 0x0804 | Toy robot. |
| TOY_VEHICLE | 0x0808 | Toy vehicle. |
| TOY_DOLL_ACTION_FIGURE | 0x080C | Humanoid toy doll. |
| TOY_CONTROLLER | 0x0810 | Toy controller. |
| TOY_GAME | 0x0814 | Toy gaming device. |
| HEALTH_UNCATEGORIZED | 0x0900 | Unclassified health devices. |
| HEALTH_BLOOD_PRESSURE | 0x0904 | Blood pressure device. |
| HEALTH_THERMOMETER | 0x0908 | Thermometer |
| HEALTH_WEIGHING | 0x090C | Body scale. |
| HEALTH_GLUCOSE | 0x0910 | Blood glucose monitor. |
| HEALTH_PULSE_OXIMETER | 0x0914 | Pulse oximeter. |
| HEALTH_PULSE_RATE | 0x0918 | Heart rate monitor. |
| HEALTH_DATA_DISPLAY | 0x091C | Health data display. |
| HEALTH_STEP_COUNTER | 0x0920 | Step counter. |
| HEALTH_BODY_COMPOSITION_ANALYZER | 0x0924 | Body composition analyzer. |
| HEALTH_PEAK_FLOW_MONITOR | 0x0928 | Hygrometer. |
| HEALTH_MEDICATION_MONITOR | 0x092C | Medication monitor. |
| HEALTH_KNEE_PROSTHESIS | 0x0930 | Prosthetic knee. |
| HEALTH_ANKLE_PROSTHESIS | 0x0934 | Prosthetic ankle. |
| HEALTH_GENERIC_HEALTH_MANAGER | 0x0938 | Generic health management device. |
| HEALTH_PERSONAL_MOBILITY_DEVICE | 0x093C | Personal mobility device. |
# @ohos.bluetooth.hfp (Bluetooth hfp Module)
The **hfp** module provides APIs for using the Bluetooth Hands-Free Profile (HFP).
> **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.
## Modules to Import
```js
import hfp from '@ohos.bluetooth.hfp';
```
## hfp.createHfpAgProfile<a name="createHfpAgProfile"></a>
createHfpAgProfile(): HandsFreeAudioGatewayProfile
Creates an **HfpAgProfile** instance.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ----------------------------- | ---------- |
| HandsFreeAudioGatewayProfile | **HfpAgProfile** instance created.|
**Example**
```js
try {
let hfpAgProfile = hfp.createHfpAgProfile();
console.info('hfpAg success');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## HandsFreeAudioGatewayProfile
Before using any API of **HandsFreeAudioGatewayProfile**, you need to create an instance of this class by using **createHfpAgProfile()**.
### connect<a name="hfp-connect"></a>
connect(deviceId: string): void
Connects to a hands-free device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| deviceId | string | Yes | Address of the remote device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let hfpAg = hfp.createHfpAgProfile();
hfpAg.connect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### disconnect<a name="hfp-disconnect"></a>
disconnect(deviceId: string): void
Disconnects from a hands-free device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| deviceId | string | Yes | Address of the remote device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let hfpAg = hfp.createHfpAgProfile();
hfpAg.disconnect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
# @ohos.bluetooth.hid (Bluetooth hid Module)
The **hid** module provides APIs for using the Bluetooth Human Interface Device Profile (HID).
> **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.
## Modules to Import
```js
import hid from '@ohos.bluetooth.hid';
```
## hid.createHidHostProfile<a name="createHidHostProfile"></a>
createHidHostProfile(): HidHostProfile
Creates a **HidHostProfile** instance.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ----------------------------- | ---------- |
| HidHostProfile | **HidHostProfile** instance created.|
**Example**
```js
try {
let hidHostProfile = hid.createHidHostProfile();
console.info('hidHost success');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## HidHostProfile
Before using any API of **HidHostProfile**, you need to create an instance of this class by using **createHidHostProfile()**.
### connect<a name="HidHost-connect"></a>
connect(deviceId: string): void
Connects to the HidHost service of a device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| deviceId | string | Yes | Address of the remote device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let hidHostProfile = hid.createHidHostProfile();
hidHostProfile.connect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### disconnect<a name="HidHost-disconnect"></a>
disconnect(deviceId: string): void
Disconnects from the HidHost service of a device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| deviceId | string | Yes | Address of the remote device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let hidHostProfile = hid.createHidHostProfile();
hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
# @ohos.bluetooth.pan (Bluetooth pan Module)
The **pan** module provides APIs for accessing the Bluetooth personal area network (PAN).
> **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.
## Modules to Import
```js
import pan from '@ohos.bluetooth.pan';
```
## pan.createPanProfile<a name="createPanProfile"></a>
createPanProfile(): PanProfile
Creates a **PanProfile** instance.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ----------------------------- | ---------- |
| PanProfile | **PanProfile** instance created.|
**Example**
```js
try {
let panProfile = pan.createPanProfile();
console.info('pan success');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## PanProfile
Before using any API of **PanProfile**, you need to create an instance of this class by using **createPanProfile()**.
### disconnect<a name="PanP-disconnect"></a>
disconnect(deviceId: string): void
Disconnects from the PAN service of a device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| deviceId | string | Yes | Address of the remote device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let panProfile = pan.createPanProfile();
panProfile.disconnect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### setTethering<a name="setTethering"></a>
setTethering(enable: boolean): void
Sets Bluetooth tethering, which shares a mobile connection.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| value | boolean | Yes | Whether to set tethering over a Bluetooth PAN.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let panProfile = pan.createPanProfile();
panProfile.setTethering(false);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### isTetheringOn<a name="isTetheringOn"></a>
isTetheringOn(): boolean
Checks whether Bluetooth tethering is activated.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| --------------------- | --------------------------------- |
| boolean | Returns **true** if tethering is available over a Bluetooth PAN; returns **false** otherwise.|
**Example**
```js
try {
let panProfile = pan.createPanProfile();
let ret = panProfile.isTetheringOn();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
# @ohos.bluetooth.socket (Bluetooth socket Module)
The **socket** module provides APIs for operating and managing Bluetooth sockets.
> **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.
## Modules to Import
```js
import socket from '@ohos.bluetooth.socket';
```
## socket.sppListen<a name="sppListen"></a>
sppListen(name: string, options: SppOptions, callback: AsyncCallback&lt;number&gt;): void
Creates a Serial Port Profile (SPP) listening socket for the server.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ----------------------- |
| name | string | Yes | Name of the service. |
| option | [SppOptions](#sppoptions) | Yes | SPP listening configuration. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the server socket ID.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
let serverNumber = -1;
function serverSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth serverSocket Number: ' + number);
serverNumber = number;
}
}
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: false, type: 0};
try {
socket.sppListen('server1', sppOption, serverSocket);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## socket.sppAccept<a name="sppAccept"></a>
sppAccept(serverSocket: number, callback: AsyncCallback&lt;number&gt;): void
Accepts a connection request from the client over a socket of the server.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------------ | --------------------------- | ---- | ----------------------- |
| serverSocket | number | Yes | Server socket ID. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the client socket ID.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
let serverNumber = -1;
function serverSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth serverSocket Number: ' + number);
serverNumber = number;
}
}
let clientNumber = -1;
function acceptClientSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth clientSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the server.
clientNumber = number;
}
}
try {
socket.sppAccept(serverNumber, acceptClientSocket);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## socket.sppConnect<a name="sppConnect"></a>
sppConnect(deviceId: string, options: SppOptions, callback: AsyncCallback&lt;number&gt;): void
Initiates an SPP connection to a remote device from the client.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ------------------------------ |
| deviceId | string | Yes | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
| option | [SppOptions](#sppoptions) | Yes | SSP listensing configuration for the connection. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the client socket ID. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: false, type: 0};
try {
socket.sppConnect('XX:XX:XX:XX:XX:XX', sppOption, clientSocket);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## socket.sppCloseServerSocket<a name="sppCloseServerSocket"></a>
sppCloseServerSocket(socket: number): void
Closes an SPP listening socket of the server.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------- |
| socket | number | Yes | Server socket ID, which is obtained by **sppListen()**. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
let serverNumber = -1;
function serverSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth serverSocket Number: ' + number);
serverNumber = number;
}
}
try {
socket.sppCloseServerSocket(serverNumber);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## socket.sppCloseClientSocket<a name="sppCloseClientSocket"></a>
sppCloseClientSocket(socket: number): void
Closes an SPP listening socket of the client.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------------- |
| socket | number | Yes | Client socket ID, which is obtained by **sppAccept()** or **sppConnect**(). |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
try {
socket.sppCloseClientSocket(clientNumber);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## socket.sppWrite<a name="sppWrite"></a>
sppWrite(clientSocket: number, data: ArrayBuffer): void
Writes data to the remote device through a socket.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------------ | ----------- | ---- | ------------- |
| clientSocket | number | Yes | Client socket ID, which is obtained by **sppAccept()** or **sppConnect**(). |
| data | ArrayBuffer | Yes | Data to write. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2901054 | IO error. |
|2900099 | Operation failed. |
**Example**
```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
let arrayBuffer = new ArrayBuffer(8);
let data = new Uint8Array(arrayBuffer);
data[0] = 123;
try {
socket.sppWrite(clientNumber, arrayBuffer);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## socket.on('sppRead')
on(type: 'sppRead', clientSocket: number, callback: Callback&lt;ArrayBuffer&gt;): void
Subscribes to SPP read request events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------------ | --------------------------- | ---- | -------------------------- |
| type | string | Yes | Event type. The value is **sppRead**, which indicates an SPP read request event. |
| clientSocket | number | Yes | Client socket ID, which is obtained by **sppAccept()** or **sppConnect()**. |
| callback | Callback&lt;ArrayBuffer&gt; | Yes | Callback invoked to return the data read. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2901054 | IO error. |
|2900099 | Operation failed. |
**Example**
```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
function dataRead(dataBuffer) {
let data = new Uint8Array(dataBuffer);
console.log('bluetooth data is: ' + data[0]);
}
try {
socket.on('sppRead', clientNumber, dataRead);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## socket.off('sppRead')
off(type: 'sppRead', clientSocket: number, callback?: Callback&lt;ArrayBuffer&gt;): void
Unsubscribes from SPP read request events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------------ | --------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **sppRead**, which indicates an SPP read request event. |
| clientSocket | number | Yes | Client socket ID, which is obtained by **sppAccept()** or **sppConnect()**. |
| callback | Callback&lt;ArrayBuffer&gt; | No | Callback for the SPP read request event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**. |
**Example**
```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
try {
socket.off('sppRead', clientNumber);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## SppOptions<a name="SppOptions"></a>
Defines the SPP configuration.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------ | ------------------- | ---- | ---- | ----------- |
| uuid | string | Yes | Yes | UUID of the SPP.|
| secure | boolean | Yes | Yes | Whether it is a secure channel. |
| type | [SppType](#SppType) | Yes | Yes | Type of the SPP link. |
## SppType<a name="SppType"></a>
Enumerates the SPP link types.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ---------- | ---- | ------------- |
| SPP_RFCOMM | 0 | Radio frequency communication (RFCOMM) link. |
...@@ -3,9 +3,8 @@ ...@@ -3,9 +3,8 @@
The **Bluetooth** module provides classic Bluetooth capabilities and Bluetooth Low Energy (BLE) scan and advertising. The **Bluetooth** module provides classic Bluetooth capabilities and Bluetooth Low Energy (BLE) scan and advertising.
> **NOTE** > **NOTE**
> > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs provided by this module are no longer maintained since API version 9. You are advised to use [bluetoothManager](js-apis-bluetoothManager.md).
> - The APIs provided by this module are no longer maintained since API version 9. You are advised to use [bluetoothManager](js-apis-bluetoothManager.md).
...@@ -215,7 +214,7 @@ let result = bluetooth.pairDevice("XX:XX:XX:XX:XX:XX"); ...@@ -215,7 +214,7 @@ let result = bluetooth.pairDevice("XX:XX:XX:XX:XX:XX");
getProfileConnState(profileId: ProfileId): ProfileConnectionState getProfileConnState(profileId: ProfileId): ProfileConnectionState
Obtains the connection status of a specified profile. Obtains the connection status of the specified profile.
> **NOTE** > **NOTE**
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getProfileConnectionState](js-apis-bluetoothManager.md#bluetoothmanagergetprofileconnectionstate). > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getProfileConnectionState](js-apis-bluetoothManager.md#bluetoothmanagergetprofileconnectionstate).
...@@ -664,7 +663,7 @@ bluetooth.off('pinRequired', onReceiveEvent); ...@@ -664,7 +663,7 @@ bluetooth.off('pinRequired', onReceiveEvent);
on(type: "bondStateChange", callback: Callback&lt;BondStateParam&gt;): void on(type: "bondStateChange", callback: Callback&lt;BondStateParam&gt;): void
Subscribes to the Bluetooth pairing state change events. Subscribes to the Bluetooth pairing state changes.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('bondStateChange')](js-apis-bluetoothManager.md#bluetoothmanageronbondstatechange). > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('bondStateChange')](js-apis-bluetoothManager.md#bluetoothmanageronbondstatechange).
...@@ -698,7 +697,7 @@ bluetooth.on('bondStateChange', onReceiveEvent); ...@@ -698,7 +697,7 @@ bluetooth.on('bondStateChange', onReceiveEvent);
off(type: "bondStateChange", callback?: Callback&lt;BondStateParam&gt;): void off(type: "bondStateChange", callback?: Callback&lt;BondStateParam&gt;): void
Unsubscribes from the Bluetooth pairing state change events. Unsubscribes from the Bluetooth pairing state changes.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('bondStateChange')](js-apis-bluetoothManager.md#bluetoothmanageroffbondstatechange). > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('bondStateChange')](js-apis-bluetoothManager.md#bluetoothmanageroffbondstatechange).
...@@ -733,7 +732,7 @@ bluetooth.off('bondStateChange', onReceiveEvent); ...@@ -733,7 +732,7 @@ bluetooth.off('bondStateChange', onReceiveEvent);
on(type: "stateChange", callback: Callback&lt;BluetoothState&gt;): void on(type: "stateChange", callback: Callback&lt;BluetoothState&gt;): void
Subscribes to the Bluetooth connection state change events. Subscribes to the Bluetooth connection state changes.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('stateChange')](js-apis-bluetoothManager.md#bluetoothmanageronstatechange). > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('stateChange')](js-apis-bluetoothManager.md#bluetoothmanageronstatechange).
...@@ -767,7 +766,7 @@ bluetooth.on('stateChange', onReceiveEvent); ...@@ -767,7 +766,7 @@ bluetooth.on('stateChange', onReceiveEvent);
off(type: "stateChange", callback?: Callback&lt;BluetoothState&gt;): void off(type: "stateChange", callback?: Callback&lt;BluetoothState&gt;): void
Unsubscribes from the Bluetooth connection state change events. Unsubscribes from the Bluetooth connection state changes.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('stateChange')](js-apis-bluetoothManager.md#bluetoothmanageroffstatechange). > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('stateChange')](js-apis-bluetoothManager.md#bluetoothmanageroffstatechange).
...@@ -1145,7 +1144,7 @@ let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE); ...@@ -1145,7 +1144,7 @@ let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
## bluetooth.BLE ## bluetooth.BLE
### bluetooth.BLE.createGattServer<sup>(deprecated)</sup> ### createGattServer<sup>(deprecated)</sup>
createGattServer(): GattServer createGattServer(): GattServer
...@@ -1169,7 +1168,7 @@ let gattServer = bluetooth.BLE.createGattServer(); ...@@ -1169,7 +1168,7 @@ let gattServer = bluetooth.BLE.createGattServer();
``` ```
### bluetooth.BLE.createGattClientDevice<sup>(deprecated)</sup> ### createGattClientDevice<sup>(deprecated)</sup>
createGattClientDevice(deviceId: string): GattClientDevice createGattClientDevice(deviceId: string): GattClientDevice
...@@ -1199,7 +1198,7 @@ let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); ...@@ -1199,7 +1198,7 @@ let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
``` ```
### bluetooth.BLE.getConnectedBLEDevices<sup>(deprecated)</sup> ### getConnectedBLEDevices<sup>(deprecated)</sup>
getConnectedBLEDevices(): Array&lt;string&gt; getConnectedBLEDevices(): Array&lt;string&gt;
...@@ -1225,7 +1224,7 @@ let result = bluetooth.BLE.getConnectedBLEDevices(); ...@@ -1225,7 +1224,7 @@ let result = bluetooth.BLE.getConnectedBLEDevices();
``` ```
### bluetooth.BLE.startBLEScan<sup>(deprecated)</sup> ### startBLEScan<sup>(deprecated)</sup>
startBLEScan(filters: Array&lt;ScanFilter&gt;, options?: ScanOptions): void startBLEScan(filters: Array&lt;ScanFilter&gt;, options?: ScanOptions): void
...@@ -1271,7 +1270,7 @@ bluetooth.BLE.startBLEScan( ...@@ -1271,7 +1270,7 @@ bluetooth.BLE.startBLEScan(
``` ```
### bluetooth.BLE.stopBLEScan<sup>(deprecated)</sup> ### stopBLEScan<sup>(deprecated)</sup>
stopBLEScan(): void stopBLEScan(): void
...@@ -1295,7 +1294,7 @@ bluetooth.BLE.stopBLEScan(); ...@@ -1295,7 +1294,7 @@ bluetooth.BLE.stopBLEScan();
``` ```
### bluetooth.BLE.on('BLEDeviceFind')<sup>(deprecated)</sup> ### on('BLEDeviceFind')<sup>(deprecated)</sup>
on(type: "BLEDeviceFind", callback: Callback&lt;Array&lt;ScanResult&gt;&gt;): void on(type: "BLEDeviceFind", callback: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
...@@ -1329,7 +1328,7 @@ bluetooth.BLE.on('BLEDeviceFind', onReceiveEvent); ...@@ -1329,7 +1328,7 @@ bluetooth.BLE.on('BLEDeviceFind', onReceiveEvent);
``` ```
### bluetooth.BLE.off('BLEDeviceFind')<sup>(deprecated)</sup> ### off('BLEDeviceFind')<sup>(deprecated)</sup>
off(type: "BLEDeviceFind", callback?: Callback&lt;Array&lt;ScanResult&gt;&gt;): void off(type: "BLEDeviceFind", callback?: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
...@@ -1502,7 +1501,7 @@ let ret = a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX'); ...@@ -1502,7 +1501,7 @@ let ret = a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX');
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the A2DP connection state change events. Subscribes to the A2DP connection state changes.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.on('connectionStateChange')](js-apis-bluetoothManager.md#onconnectionstatechange). > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.on('connectionStateChange')](js-apis-bluetoothManager.md#onconnectionstatechange).
...@@ -1535,7 +1534,7 @@ a2dpSrc.on('connectionStateChange', onReceiveEvent); ...@@ -1535,7 +1534,7 @@ a2dpSrc.on('connectionStateChange', onReceiveEvent);
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the A2DP connection state change events. Unsubscribes from the A2DP connection state changes.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.off('connectionStateChange')](js-apis-bluetoothManager.md#offconnectionstatechange). > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.off('connectionStateChange')](js-apis-bluetoothManager.md#offconnectionstatechange).
...@@ -1673,7 +1672,7 @@ let ret = hfpAg.disconnect('XX:XX:XX:XX:XX:XX'); ...@@ -1673,7 +1672,7 @@ let ret = hfpAg.disconnect('XX:XX:XX:XX:XX:XX');
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the HFP connection state change events. Subscribes to the HFP connection state changes.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.HandsFreeAudioGatewayProfile.on('connectionStateChange')](js-apis-bluetoothManager.md#onconnectionstatechange-1). > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.HandsFreeAudioGatewayProfile.on('connectionStateChange')](js-apis-bluetoothManager.md#onconnectionstatechange-1).
...@@ -1707,7 +1706,7 @@ hfpAg.on('connectionStateChange', onReceiveEvent); ...@@ -1707,7 +1706,7 @@ hfpAg.on('connectionStateChange', onReceiveEvent);
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the HFP connection state change events. Unsubscribes from the HFP connection state changes.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.HandsFreeAudioGatewayProfile.off('connectionStateChange')](js-apis-bluetoothManager.md#offconnectionstatechange-1). > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.HandsFreeAudioGatewayProfile.off('connectionStateChange')](js-apis-bluetoothManager.md#offconnectionstatechange-1).
...@@ -2394,7 +2393,7 @@ gattServer.off("descriptorWrite"); ...@@ -2394,7 +2393,7 @@ gattServer.off("descriptorWrite");
on(type: "connectStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void on(type: "connectStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
Subscribes to the BLE connection state change events. Subscribes to the BLE connection state changes.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.on('connectStateChange')](js-apis-bluetoothManager.md#onconnectstatechange). > This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.on('connectStateChange')](js-apis-bluetoothManager.md#onconnectstatechange).
...@@ -2431,7 +2430,7 @@ gattServer.on("connectStateChange", Connected); ...@@ -2431,7 +2430,7 @@ gattServer.on("connectStateChange", Connected);
off(type: "connectStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void off(type: "connectStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void
Unsubscribes from the BLE connection state change events. Unsubscribes from the BLE connection state changes.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.off('connectStateChange')](js-apis-bluetoothManager.md#offconnectstatechange). > This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.off('connectStateChange')](js-apis-bluetoothManager.md#offconnectstatechange).
...@@ -2995,7 +2994,7 @@ device.setNotifyCharacteristicChanged(characteristic, false); ...@@ -2995,7 +2994,7 @@ device.setNotifyCharacteristicChanged(characteristic, false);
on(type: "BLECharacteristicChange", callback: Callback&lt;BLECharacteristic&gt;): void on(type: "BLECharacteristicChange", callback: Callback&lt;BLECharacteristic&gt;): void
Subscribes to the BLE characteristic change events. The client can receive a notification from the server only after the **setNotifyCharacteristicChanged** method is called. Subscribes to the BLE characteristic changes. The client can receive a notification from the server only after the **setNotifyCharacteristicChanged** method is called.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.on('BLECharacteristicChange')](js-apis-bluetoothManager.md#onblecharacteristicchange). > This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.on('BLECharacteristicChange')](js-apis-bluetoothManager.md#onblecharacteristicchange).
...@@ -3032,7 +3031,7 @@ device.on('BLECharacteristicChange', CharacteristicChange); ...@@ -3032,7 +3031,7 @@ device.on('BLECharacteristicChange', CharacteristicChange);
off(type: "BLECharacteristicChange", callback?: Callback&lt;BLECharacteristic&gt;): void off(type: "BLECharacteristicChange", callback?: Callback&lt;BLECharacteristic&gt;): void
Unsubscribes from the BLE characteristic change events. Unsubscribes from the BLE characteristic changes.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.off('BLECharacteristicChange')](js-apis-bluetoothManager.md#offblecharacteristicchange). > This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.off('BLECharacteristicChange')](js-apis-bluetoothManager.md#offblecharacteristicchange).
...@@ -3064,7 +3063,7 @@ device.off('BLECharacteristicChange'); ...@@ -3064,7 +3063,7 @@ device.off('BLECharacteristicChange');
on(type: "BLEConnectionStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void on(type: "BLEConnectionStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
Subscribes to the BLE connection state change events. Subscribes to the BLE connection state changes.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.on('BLEConnectionStateChange')](js-apis-bluetoothManager.md#onbleconnectionstatechange). > This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.on('BLEConnectionStateChange')](js-apis-bluetoothManager.md#onbleconnectionstatechange).
...@@ -3100,7 +3099,7 @@ device.on('BLEConnectionStateChange', ConnectStateChanged); ...@@ -3100,7 +3099,7 @@ device.on('BLEConnectionStateChange', ConnectStateChanged);
off(type: "BLEConnectionStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void off(type: "BLEConnectionStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void
Unsubscribes from the BLE connection state change events. Unsubscribes from the BLE connection state changes.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.off('BLEConnectionStateChange')](js-apis-bluetoothManager.md#offbleconnectionstatechange). > This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.off('BLEConnectionStateChange')](js-apis-bluetoothManager.md#offbleconnectionstatechange).
......
...@@ -15,12 +15,15 @@ import bluetoothManager from '@ohos.bluetoothManager'; ...@@ -15,12 +15,15 @@ import bluetoothManager from '@ohos.bluetoothManager';
``` ```
## bluetoothManager.enableBluetooth<a name="enableBluetooth"></a> ## bluetoothManager.enableBluetooth<sup>(deprecated)</sup><a name="enableBluetooth"></a>
enableBluetooth(): void enableBluetooth(): void
Enables Bluetooth. Enables Bluetooth.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [access.enableBluetooth](js-apis-bluetooth-access.md#accessenablebluetooth).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -45,12 +48,15 @@ try { ...@@ -45,12 +48,15 @@ try {
``` ```
## bluetoothManager.disableBluetooth<a name="disableBluetooth"></a> ## bluetoothManager.disableBluetooth<sup>(deprecated)</sup><a name="disableBluetooth"></a>
disableBluetooth(): void disableBluetooth(): void
Disables Bluetooth. Disables Bluetooth.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [access.disableBluetooth](js-apis-bluetooth-access.md#accessdisablebluetooth).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -75,12 +81,15 @@ try { ...@@ -75,12 +81,15 @@ try {
``` ```
## bluetoothManager.getLocalName<a name="getLocalName"></a> ## bluetoothManager.getLocalName<sup>(deprecated)</sup><a name="getLocalName"></a>
getLocalName(): string getLocalName(): string
Obtains the name of the local Bluetooth device. Obtains the name of the local Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getLocalName](js-apis-bluetooth-connection.md#connectiongetlocalname).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -111,12 +120,15 @@ try { ...@@ -111,12 +120,15 @@ try {
``` ```
## bluetoothManager.getState ## bluetoothManager.getState<sup>(deprecated)</sup>
getState(): BluetoothState getState(): BluetoothState
Obtains the Bluetooth state. Obtains the Bluetooth state.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [access.getState](js-apis-bluetooth-access.md#accessgetstate).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -147,12 +159,15 @@ try { ...@@ -147,12 +159,15 @@ try {
``` ```
## bluetoothManager.getBtConnectionState ## bluetoothManager.getBtConnectionState<sup>(deprecated)</sup>
getBtConnectionState(): ProfileConnectionState getBtConnectionState(): ProfileConnectionState
Obtains the local profile connection status. Obtains the local profile connection status.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getProfileConnectionState](js-apis-bluetooth-connection.md#connectiongetprofileconnectionstate).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -184,12 +199,15 @@ try { ...@@ -184,12 +199,15 @@ try {
``` ```
## bluetoothManager.setLocalName<a name="setLocalName"></a> ## bluetoothManager.setLocalName<sup>(deprecated)</sup><a name="setLocalName"></a>
setLocalName(name: string): void setLocalName(name: string): void
Sets the name of the local Bluetooth device. Sets the name of the local Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.setLocalName](js-apis-bluetooth-connection.md#connectionsetlocalname).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -221,12 +239,15 @@ try { ...@@ -221,12 +239,15 @@ try {
``` ```
## bluetoothManager.pairDevice ## bluetoothManager.pairDevice<sup>(deprecated)</sup>
pairDevice(deviceId: string): void pairDevice(deviceId: string): void
Initiates Bluetooth pairing. Initiates Bluetooth pairing.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.pairDevice](js-apis-bluetooth-connection.md#connectionpairdevice).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -259,109 +280,15 @@ try { ...@@ -259,109 +280,15 @@ try {
``` ```
## bluetoothManager.pairCredibleDevice<sup>10+</sup> ## bluetoothManager.getProfileConnectionState<sup>(deprecated)</sup><a name="getProfileConnectionState"></a>
pairCredibleDevice(deviceId: string, transport: BluetoothTransport, callback: AsyncCallback&lt;void&gt;): void
Pairs a trusted remote device whose address is obtained in a non-Bluetooth scan mode (such as using NFC).
**System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the remote device to pair, for example, XX:XX:XX:XX:XX:XX.|
| transport | [BluetoothTransport](#bluetoothtransport10) | Yes | Device type, for example, a classic Bluetooth device or a Bluetooth low energy (BLE) device.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
bluetoothManager.pairCredibleDevice("68:13:24:79:4C:8C", 1, err => {
if (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
return;
}
console.info("pairCredibleDevice,err:" + JSON.stringify(err));
});
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.pairCredibleDevice<sup>10+</sup>
pairCredibleDevice(deviceId: string, transport: BluetoothTransport): Promise&lt;void&gt;
Pairs a trusted remote device whose address is obtained in a non-Bluetooth scan mode (such as using NFC).
**System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the remote device to pair, for example, XX:XX:XX:XX:XX:XX.|
| transport | [BluetoothTransport](#bluetoothtransport10) | Yes | Device type, for example, a classic Bluetooth device or a BLE device.|
**Return value**
| Type | Description |
| ------------------------------------------------- | ------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
bluetoothManager.pairCredibleDevice("68:13:24:79:4C:8C", 0).then(() => {
console.info("PairCredibleDevice");
}, err => {
console.error("PairCredibleDevice:errCode" + err.code + ",errMessage:" + err.message);
});
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.getProfileConnectionState<a name="getProfileConnectionState"></a>
getProfileConnectionState(profileId: ProfileId): ProfileConnectionState getProfileConnectionState(profileId: ProfileId): ProfileConnectionState
Obtains the connection status of the specified profile. Obtains the connection status of the specified profile.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getProfileConnectionState](js-apis-bluetooth-connection.md#connectiongetprofileconnectionstate).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -400,12 +327,15 @@ try { ...@@ -400,12 +327,15 @@ try {
``` ```
## bluetoothManager.cancelPairedDevice<a name="cancelPairedDevice"></a> ## bluetoothManager.cancelPairedDevice<sup>(deprecated)</sup><a name="cancelPairedDevice"></a>
cancelPairedDevice(deviceId: string): void cancelPairedDevice(deviceId: string): void
Cancels a paired remote device. Cancels a paired remote device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.cancelPairedDevice](js-apis-bluetooth-connection.md#connectioncancelpaireddevice).
**System API**: This is a system API. **System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
...@@ -439,12 +369,15 @@ try { ...@@ -439,12 +369,15 @@ try {
``` ```
## bluetoothManager.getRemoteDeviceName<a name="getRemoteDeviceName"></a> ## bluetoothManager.getRemoteDeviceName<sup>(deprecated)</sup><a name="getRemoteDeviceName"></a>
getRemoteDeviceName(deviceId: string): string getRemoteDeviceName(deviceId: string): string
Obtains the name of the remote Bluetooth device. Obtains the name of the remote Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getRemoteDeviceName](js-apis-bluetooth-connection.md#connectiongetremotedevicename).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -482,12 +415,15 @@ try { ...@@ -482,12 +415,15 @@ try {
``` ```
## bluetoothManager.getRemoteDeviceClass<a name="getRemoteDeviceClass"></a> ## bluetoothManager.getRemoteDeviceClass<sup>(deprecated)</sup><a name="getRemoteDeviceClass"></a>
getRemoteDeviceClass(deviceId: string): DeviceClass getRemoteDeviceClass(deviceId: string): DeviceClass
Obtains the class of the remote Bluetooth device. Obtains the class of the remote Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getRemoteDeviceClass](js-apis-bluetooth-connection.md#connectiongetremotedeviceclass).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -525,12 +461,15 @@ try { ...@@ -525,12 +461,15 @@ try {
``` ```
## bluetoothManager.getPairedDevices<a name="getPairedDevices"></a> ## bluetoothManager.getPairedDevices<sup>(deprecated)</sup><a name="getPairedDevices"></a>
getPairedDevices(): Array&lt;string&gt; getPairedDevices(): Array&lt;string&gt;
Obtains the paired devices. Obtains the paired devices.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getPairedDevices](js-apis-bluetooth-connection.md#connectiongetpaireddevices).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -562,12 +501,15 @@ try { ...@@ -562,12 +501,15 @@ try {
``` ```
## bluetoothManager.setBluetoothScanMode<a name="setBluetoothScanMode"></a> ## bluetoothManager.setBluetoothScanMode<sup>(deprecated)</sup><a name="setBluetoothScanMode"></a>
setBluetoothScanMode(mode: ScanMode, duration: number): void setBluetoothScanMode(mode: ScanMode, duration: number): void
Sets the Bluetooth scan mode so that the device can be discovered by a remote device. Sets the Bluetooth scan mode so that the device can be discovered by a remote device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.setBluetoothScanMode](js-apis-bluetooth-connection.md#connectionsetbluetoothscanmode).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -601,12 +543,15 @@ try { ...@@ -601,12 +543,15 @@ try {
``` ```
## bluetoothManager.getBluetoothScanMode<a name="getBluetoothScanMode"></a> ## bluetoothManager.getBluetoothScanMode<sup>(deprecated)</sup><a name="getBluetoothScanMode"></a>
getBluetoothScanMode(): ScanMode getBluetoothScanMode(): ScanMode
Obtains the Bluetooth scan mode. Obtains the Bluetooth scan mode.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getBluetoothScanMode](js-apis-bluetooth-connection.md#connectiongetbluetoothscanmode).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -638,12 +583,15 @@ try { ...@@ -638,12 +583,15 @@ try {
``` ```
## bluetoothManager.startBluetoothDiscovery<a name="startBluetoothDiscovery"></a> ## bluetoothManager.startBluetoothDiscovery<sup>(deprecated)</sup><a name="startBluetoothDiscovery"></a>
startBluetoothDiscovery(): void startBluetoothDiscovery(): void
Starts Bluetooth scan to discover remote devices. Starts Bluetooth scan to discover remote devices.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.startBluetoothDiscovery](js-apis-bluetooth-connection.md#connectionstartbluetoothdiscovery).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH and ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH and ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -674,12 +622,15 @@ try { ...@@ -674,12 +622,15 @@ try {
``` ```
## bluetoothManager.stopBluetoothDiscovery<a name="stopBluetoothDiscovery"></a> ## bluetoothManager.stopBluetoothDiscovery<sup>(deprecated)</sup><a name="stopBluetoothDiscovery"></a>
stopBluetoothDiscovery(): void stopBluetoothDiscovery(): void
Stops Bluetooth scan. Stops Bluetooth scan.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.stopBluetoothDiscovery](js-apis-bluetooth-connection.md#connectionstopbluetoothdiscovery).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -705,12 +656,15 @@ try { ...@@ -705,12 +656,15 @@ try {
``` ```
## bluetoothManager.setDevicePairingConfirmation<a name="setDevicePairingConfirmation"></a> ## bluetoothManager.setDevicePairingConfirmation<sup>(deprecated)</sup><a name="setDevicePairingConfirmation"></a>
setDevicePairingConfirmation(device: string, accept: boolean): void setDevicePairingConfirmation(device: string, accept: boolean): void
Sets the device pairing confirmation. Sets the device pairing confirmation.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.setDevicePairingConfirmation](js-apis-bluetooth-connection.md#connectionsetdevicepairingconfirmation).
**Required permissions**: ohos.permission.MANAGE_BLUETOOTH **Required permissions**: ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -749,104 +703,15 @@ try { ...@@ -749,104 +703,15 @@ try {
``` ```
## bluetoothManager.setDevicePinCode<sup>10+</sup><a name="setDevicePinCode"></a> ## bluetoothManager.on('bluetoothDeviceFind')<sup>(deprecated)</sup>
setDevicePinCode(device: string, code: string, callback: AsyncCallback&lt;void&gt;): void
Sets the PIN for the device when [PinType](#pintype10) is **PIN_TYPE_ENTER_PIN_CODE** or **PIN_TYPE_PIN_16_DIGITS**.
**Required permissions**: ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------- | ---- | -------------------------------- |
| device | string | Yes | MAC address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
| code | string | Yes | PIN to set. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
//callback
try {
bluetoothManager.setDevicePinCode('11:22:33:44:55:66', '12345', (err, data) => {
console.info('setDevicePinCode,device name err:' + JSON.stringify(err) + ',device name:' + JSON.stringify(data));
});
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.setDevicePinCode<sup>10+</sup><a name="setDevicePinCode-1"></a>
setDevicePinCode(device: string, code: string): Promise&lt;void&gt;
Sets the PIN for the device when [PinType](#pintype10) is **PIN_TYPE_ENTER_PIN_CODE** or **PIN_TYPE_PIN_16_DIGITS**. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------- | ---- | -------------------------------- |
| device | string | Yes | MAC address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
| code | string | Yes | PIN to set. |
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
//promise
try {
bluetoothManager.setDevicePinCode('11:22:33:44:55:66', '12345').then(() => {
console.info('setDevicePinCode');
}, error => {
console.info('setDevicePinCode: errCode:' + error.code + ',errMessage' + error.message);
})
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.on('bluetoothDeviceFind')
on(type: "bluetoothDeviceFind", callback: Callback&lt;Array&lt;string&gt;&gt;): void on(type: "bluetoothDeviceFind", callback: Callback&lt;Array&lt;string&gt;&gt;): void
Subscribes to the Bluetooth device discovery events. Subscribes to the Bluetooth device discovery events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.on('bluetoothDeviceFind')](js-apis-bluetooth-connection.md#connectiononbluetoothdevicefind).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -880,12 +745,15 @@ try { ...@@ -880,12 +745,15 @@ try {
``` ```
## bluetoothManager.off('bluetoothDeviceFind') ## bluetoothManager.off('bluetoothDeviceFind')<sup>(deprecated)</sup>
off(type: "bluetoothDeviceFind", callback?: Callback&lt;Array&lt;string&gt;&gt;): void off(type: "bluetoothDeviceFind", callback?: Callback&lt;Array&lt;string&gt;&gt;): void
Unsubscribes from the Bluetooth device discovery events. Unsubscribes from the Bluetooth device discovery events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.off('bluetoothDeviceFind')](js-apis-bluetooth-connection.md#connectionoffbluetoothdevicefind).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -920,12 +788,15 @@ try { ...@@ -920,12 +788,15 @@ try {
``` ```
## bluetoothManager.on('pinRequired') ## bluetoothManager.on('pinRequired')<sup>(deprecated)</sup>
on(type: "pinRequired", callback: Callback&lt;PinRequiredParam&gt;): void on(type: "pinRequired", callback: Callback&lt;PinRequiredParam&gt;): void
Subscribes to the pairing request events of the remote Bluetooth device. Subscribes to the pairing request events of the remote Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.on('pinRequired')](js-apis-bluetooth-connection.md#connectiononpinrequired).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -959,12 +830,15 @@ try { ...@@ -959,12 +830,15 @@ try {
``` ```
## bluetoothManager.off('pinRequired') ## bluetoothManager.off('pinRequired')<sup>(deprecated)</sup>
off(type: "pinRequired", callback?: Callback&lt;PinRequiredParam&gt;): void off(type: "pinRequired", callback?: Callback&lt;PinRequiredParam&gt;): void
Unsubscribes from the pairing request events of the remote Bluetooth device. Unsubscribes from the pairing request events of the remote Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.off('pinRequired')](js-apis-bluetooth-connection.md#connectionoffpinrequired).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -999,11 +873,14 @@ try { ...@@ -999,11 +873,14 @@ try {
``` ```
## bluetoothManager.on('bondStateChange') ## bluetoothManager.on('bondStateChange')<sup>(deprecated)</sup>
on(type: "bondStateChange", callback: Callback&lt;BondStateParam&gt;): void on(type: "bondStateChange", callback: Callback&lt;BondStateParam&gt;): void
Subscribes to the Bluetooth pairing state change events. Subscribes to the Bluetooth pairing state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.on('bondStateChange')](js-apis-bluetooth-connection.md#connectiononbondstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -1038,11 +915,14 @@ try { ...@@ -1038,11 +915,14 @@ try {
``` ```
## bluetoothManager.off('bondStateChange') ## bluetoothManager.off('bondStateChange')<sup>(deprecated)</sup>
off(type: "bondStateChange", callback?: Callback&lt;BondStateParam&gt;): void off(type: "bondStateChange", callback?: Callback&lt;BondStateParam&gt;): void
Unsubscribes from the Bluetooth pairing state change events. Unsubscribes from the Bluetooth pairing state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.off('bondStateChange')](js-apis-bluetooth-connection.md#connectionoffbondstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -1078,12 +958,15 @@ try { ...@@ -1078,12 +958,15 @@ try {
``` ```
## bluetoothManager.on('stateChange') ## bluetoothManager.on('stateChange')<sup>(deprecated)</sup>
on(type: "stateChange", callback: Callback&lt;BluetoothState&gt;): void on(type: "stateChange", callback: Callback&lt;BluetoothState&gt;): void
Subscribes to Bluetooth state events. Subscribes to Bluetooth state events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [access.on('stateChange')](js-apis-bluetooth-access.md#accessonstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1117,12 +1000,15 @@ try { ...@@ -1117,12 +1000,15 @@ try {
``` ```
## bluetoothManager.off('stateChange') ## bluetoothManager.off('stateChange')<sup>(deprecated)</sup>
off(type: "stateChange", callback?: Callback&lt;BluetoothState&gt;): void off(type: "stateChange", callback?: Callback&lt;BluetoothState&gt;): void
Unsubscribes from Bluetooth state events. Unsubscribes from Bluetooth state events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [access.off('stateChange')](js-apis-bluetooth-access.md#accessoffstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1157,12 +1043,15 @@ try { ...@@ -1157,12 +1043,15 @@ try {
``` ```
## bluetoothManager.sppListen<a name="sppListen"></a> ## bluetoothManager.sppListen<sup>(deprecated)</sup><a name="sppListen"></a>
sppListen(name: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void sppListen(name: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void
Creates a server listening socket. Creates a server listening socket.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.sppListen](js-apis-bluetooth-socket.md#socketspplisten).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1207,12 +1096,15 @@ try { ...@@ -1207,12 +1096,15 @@ try {
``` ```
## bluetoothManager.sppAccept<a name="sppAccept"></a> ## bluetoothManager.sppAccept<sup>(deprecated)</sup><a name="sppAccept"></a>
sppAccept(serverSocket: number, callback: AsyncCallback&lt;number&gt;): void sppAccept(serverSocket: number, callback: AsyncCallback&lt;number&gt;): void
Listens for a connection to be made to this socket from the client and accepts it. Listens for a connection to be made to this socket from the client and accepts it.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.sppAccept](js-apis-bluetooth-socket.md#socketsppaccept).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1261,12 +1153,15 @@ try { ...@@ -1261,12 +1153,15 @@ try {
``` ```
## bluetoothManager.sppConnect<a name="sppConnect"></a> ## bluetoothManager.sppConnect<sup>(deprecated)</sup><a name="sppConnect"></a>
sppConnect(device: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void sppConnect(device: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void
Initiates an SPP connection to a remote device from the client. Initiates an SPP connection to a remote device from the client.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.sppConnect](js-apis-bluetooth-socket.md#socketsppconnect).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1312,12 +1207,15 @@ try { ...@@ -1312,12 +1207,15 @@ try {
``` ```
## bluetoothManager.sppCloseServerSocket<a name="sppCloseServerSocket"></a> ## bluetoothManager.sppCloseServerSocket<sup>(deprecated)</sup><a name="sppCloseServerSocket"></a>
sppCloseServerSocket(socket: number): void sppCloseServerSocket(socket: number): void
Closes the listening socket of the server. Closes the listening socket of the server.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.sppCloseServerSocket](js-apis-bluetooth-socket.md#socketsppcloseserversocket).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1354,12 +1252,15 @@ try { ...@@ -1354,12 +1252,15 @@ try {
``` ```
## bluetoothManager.sppCloseClientSocket<a name="sppCloseClientSocket"></a> ## bluetoothManager.sppCloseClientSocket<sup>(deprecated)</sup><a name="sppCloseClientSocket"></a>
sppCloseClientSocket(socket: number): void sppCloseClientSocket(socket: number): void
Closes the client socket. Closes the client socket.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.sppCloseClientSocket](js-apis-bluetooth-socket.md#socketsppcloseclientsocket).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1398,12 +1299,15 @@ try { ...@@ -1398,12 +1299,15 @@ try {
``` ```
## bluetoothManager.sppWrite<a name="sppWrite"></a> ## bluetoothManager.sppWrite<sup>(deprecated)</sup><a name="sppWrite"></a>
sppWrite(clientSocket: number, data: ArrayBuffer): void sppWrite(clientSocket: number, data: ArrayBuffer): void
Writes data to the remote device through the socket. Writes data to the remote device through the socket.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.sppWrite](js-apis-bluetooth-socket.md#socketsppwrite).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1445,12 +1349,15 @@ try { ...@@ -1445,12 +1349,15 @@ try {
``` ```
## bluetoothManager.on('sppRead') ## bluetoothManager.on('sppRead')<sup>(deprecated)</sup>
on(type: "sppRead", clientSocket: number, callback: Callback&lt;ArrayBuffer&gt;): void on(type: "sppRead", clientSocket: number, callback: Callback&lt;ArrayBuffer&gt;): void
Subscribes to the SPP read request events. Subscribes to the SPP read request events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.on('sppRead')](js-apis-bluetooth-socket.md#socketonsppread).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1494,12 +1401,15 @@ try { ...@@ -1494,12 +1401,15 @@ try {
``` ```
## bluetoothManager.off('sppRead') ## bluetoothManager.off('sppRead')<sup>(deprecated)</sup>
off(type: "sppRead", clientSocket: number, callback?: Callback&lt;ArrayBuffer&gt;): void off(type: "sppRead", clientSocket: number, callback?: Callback&lt;ArrayBuffer&gt;): void
Unsubscribes from the SPP read request events. Unsubscribes from the SPP read request events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.off('sppRead')](js-apis-bluetooth-socket.md#socketoffsppread).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1529,7 +1439,7 @@ try { ...@@ -1529,7 +1439,7 @@ try {
} }
``` ```
## bluetoothManager.getProfileInstance<a name="getProfileInstance"></a> ## bluetoothManager.getProfileInstance<sup>(deprecated)</sup><a name="getProfileInstance"></a>
getProfileInstance(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile | HidHostProfile | PanProfile getProfileInstance(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile | HidHostProfile | PanProfile
...@@ -1562,12 +1472,15 @@ try { ...@@ -1562,12 +1472,15 @@ try {
## bluetoothManager.BLE ## bluetoothManager.BLE
### bluetoothManager.BLE.createGattServer ### createGattServer<sup>(deprecated)</sup>
createGattServer(): GattServer createGattServer(): GattServer
Creates a **GattServer** instance. Creates a **GattServer** instance.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.createGattServer](js-apis-bluetooth-ble.md#blecreategattserver).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value** **Return value**
...@@ -1583,12 +1496,15 @@ let gattServer = bluetoothManager.BLE.createGattServer(); ...@@ -1583,12 +1496,15 @@ let gattServer = bluetoothManager.BLE.createGattServer();
``` ```
### bluetoothManager.BLE.createGattClientDevice ### createGattClientDevice<sup>(deprecated)</sup>
createGattClientDevice(deviceId: string): GattClientDevice createGattClientDevice(deviceId: string): GattClientDevice
Creates a **GattClientDevice** instance. Creates a **GattClientDevice** instance.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.createGattClientDevice](js-apis-bluetooth-ble.md#blecreategattclientdevice).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1614,12 +1530,15 @@ try { ...@@ -1614,12 +1530,15 @@ try {
``` ```
### bluetoothManager.BLE.getConnectedBLEDevices ### getConnectedBLEDevices<sup>(deprecated)</sup>
getConnectedBLEDevices(): Array&lt;string&gt; getConnectedBLEDevices(): Array&lt;string&gt;
Obtains the BLE devices connected to this device. Obtains the BLE devices connected to this device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.getConnectedBLEDevices](js-apis-bluetooth-ble.md#blegetconnectedbledevices).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1651,12 +1570,15 @@ try { ...@@ -1651,12 +1570,15 @@ try {
``` ```
### bluetoothManager.BLE.startBLEScan ### startBLEScan<sup>(deprecated)</sup>
startBLEScan(filters: Array&lt;ScanFilter&gt;, options?: ScanOptions): void startBLEScan(filters: Array&lt;ScanFilter&gt;, options?: ScanOptions): void
Starts a BLE scan. Starts a BLE scan.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.startBLEScan](js-apis-bluetooth-ble.md#blestartblescan).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH, ohos.permission.MANAGE_BLUETOOTH, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH, ohos.permission.MANAGE_BLUETOOTH, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1704,12 +1626,15 @@ try { ...@@ -1704,12 +1626,15 @@ try {
``` ```
### bluetoothManager.BLE.stopBLEScan ### stopBLEScan<sup>(deprecated)</sup>
stopBLEScan(): void stopBLEScan(): void
Stops the BLE scan. Stops the BLE scan.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.startBLEScan](js-apis-bluetooth-ble.md#blestopblescan).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1735,12 +1660,15 @@ try { ...@@ -1735,12 +1660,15 @@ try {
``` ```
### bluetoothManager.BLE.on('BLEDeviceFind') ### on('BLEDeviceFind')<sup>(deprecated)</sup>
on(type: "BLEDeviceFind", callback: Callback&lt;Array&lt;ScanResult&gt;&gt;): void on(type: "BLEDeviceFind", callback: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
Subscribe to the BLE device discovery events. Subscribe to the BLE device discovery events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.on('BLEDeviceFind')](js-apis-bluetooth-ble.md#bleonbledevicefind).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1774,12 +1702,15 @@ try { ...@@ -1774,12 +1702,15 @@ try {
``` ```
### bluetoothManager.BLE.off('BLEDeviceFind') ### off('BLEDeviceFind')<sup>(deprecated)</sup>
off(type: "BLEDeviceFind", callback?: Callback&lt;Array&lt;ScanResult&gt;&gt;): void off(type: "BLEDeviceFind", callback?: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
Unsubscribes from the BLE device discovery events. Unsubscribes from the BLE device discovery events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.off('BLEDeviceFind')](js-apis-bluetooth-ble.md#bleoffbledevicefind).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1819,12 +1750,15 @@ try { ...@@ -1819,12 +1750,15 @@ try {
Provides the profile base class. Provides the profile base class.
### getConnectionDevices<a name="getConnectionDevices"></a> ### getConnectionDevices<sup>(deprecated)</sup><a name="getConnectionDevices"></a>
getConnectionDevices(): Array&lt;string&gt; getConnectionDevices(): Array&lt;string&gt;
Obtains the connected devices. Obtains the connected devices.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.getConnectedDevices](js-apis-bluetooth-baseProfile.md#baseprofilegetconnecteddevices).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1857,12 +1791,15 @@ try { ...@@ -1857,12 +1791,15 @@ try {
} }
``` ```
### getDeviceState<a name="getDeviceState"></a> ### getDeviceState<sup>(deprecated)</sup><a name="getDeviceState"></a>
getDeviceState(device: string): ProfileConnectionState getDeviceState(device: string): ProfileConnectionState
Obtains the connection state of the profile. Obtains the connection state of the profile.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.getConnectionState](js-apis-bluetooth-baseProfile.md#baseprofilegetconnectionstate).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1901,17 +1838,24 @@ try { ...@@ -1901,17 +1838,24 @@ try {
} }
``` ```
## A2dpSourceProfile ## A2dpSourceProfile
Before using an API of **A2dpSourceProfile**, you need to create an instance of this class by using **getProfile()**. Before using an API of **A2dpSourceProfile**, you need to create an instance of this class by using **getProfile()**.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [a2dp.A2dpSourceProfile](js-apis-bluetooth-a2dp.md#a2dpsourceprofile).
### connect<a name="a2dp-connect"></a>
### connect<sup>(deprecated)</sup><a name="a2dp-connect"></a>
connect(device: string): void connect(device: string): void
Sets up an Advanced Audio Distribution Profile (A2DP) connection. Sets up an Advanced Audio Distribution Profile (A2DP) connection.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [a2dp.A2dpSourceProfile#connect](js-apis-bluetooth-a2dp.md#connect).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1945,12 +1889,15 @@ try { ...@@ -1945,12 +1889,15 @@ try {
``` ```
### disconnect<a name="a2dp-disconnect"></a> ### disconnect<sup>(deprecated)</sup><a name="a2dp-disconnect"></a>
disconnect(device: string): void disconnect(device: string): void
Disconnects an A2DP connection. Disconnects an A2DP connection.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [a2dp.A2dpSourceProfile#disconnect](js-apis-bluetooth-a2dp.md#disconnect).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1984,11 +1931,14 @@ try { ...@@ -1984,11 +1931,14 @@ try {
``` ```
### on('connectionStateChange') ### on('connectionStateChange')<sup>(deprecated)</sup>
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the A2DP connection state change events. Subscribes to the A2DP connection state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.on('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileonconnectionstatechange).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1996,7 +1946,7 @@ Subscribes to the A2DP connection state change events. ...@@ -1996,7 +1946,7 @@ Subscribes to the A2DP connection state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates an A2DP connection state change event.| | type | string | Yes | Event type. The value **connectionStateChange** indicates a A2DP connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the A2DP connection state change event. | | callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the A2DP connection state change event. |
**Return value** **Return value**
...@@ -2014,11 +1964,14 @@ a2dpSrc.on('connectionStateChange', onReceiveEvent); ...@@ -2014,11 +1964,14 @@ a2dpSrc.on('connectionStateChange', onReceiveEvent);
``` ```
### off('connectionStateChange') ### off('connectionStateChange')<sup>(deprecated)</sup>
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the A2DP connection state change events. Unsubscribes from the A2DP connection state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.off('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileoffconnectionstatechange).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2026,7 +1979,7 @@ Unsubscribes from the A2DP connection state change events. ...@@ -2026,7 +1979,7 @@ Unsubscribes from the A2DP connection state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates an A2DP connection state change event.| | type | string | Yes | Event type. The value **connectionStateChange** indicates a A2DP connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the A2DP connection state change event. | | callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the A2DP connection state change event. |
**Return value** **Return value**
...@@ -2045,12 +1998,15 @@ a2dpSrc.off('connectionStateChange', onReceiveEvent); ...@@ -2045,12 +1998,15 @@ a2dpSrc.off('connectionStateChange', onReceiveEvent);
``` ```
### getPlayingState ### getPlayingState<sup>(deprecated)</sup>
getPlayingState(device: string): PlayingState getPlayingState(device: string): PlayingState
Obtains the playing state of a device. Obtains the playing state of a device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [a2dp.A2dpSourceProfile#getPlayingState](js-apis-bluetooth-a2dp.md#getPlayingState).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -2088,10 +2044,13 @@ try { ...@@ -2088,10 +2044,13 @@ try {
``` ```
## HandsFreeAudioGatewayProfile ## HandsFreeAudioGatewayProfile<sup>(deprecated)</sup>
Before using an API of **HandsFreeAudioGatewayProfile**, you need to create an instance of this class by using **getProfile()**. Before using an API of **HandsFreeAudioGatewayProfile**, you need to create an instance of this class by using **getProfile()**.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [hfp.HandsFreeAudioGatewayProfile](js-apis-bluetooth-hfp.md#HandsFreeAudioGatewayProfile).
### connect<a name="hfp-connect"></a> ### connect<a name="hfp-connect"></a>
...@@ -2099,6 +2058,9 @@ connect(device: string): void ...@@ -2099,6 +2058,9 @@ connect(device: string): void
Sets up a Hands-free Profile (HFP) connection of a device. Sets up a Hands-free Profile (HFP) connection of a device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [hfp.HandsFreeAudioGatewayProfile#connect](js-apis-bluetooth-hfp.md#connect).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2132,12 +2094,15 @@ try { ...@@ -2132,12 +2094,15 @@ try {
``` ```
### disconnect<a name="hfp-disconnect"></a> ### disconnect<sup>(deprecated)</sup><a name="hfp-disconnect"></a>
disconnect(device: string): void disconnect(device: string): void
Disconnects the HFP connection of a device. Disconnects the HFP connection of a device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [hfp.HandsFreeAudioGatewayProfile#disconnect](js-apis-bluetooth-hfp.md#disconnect).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2171,11 +2136,14 @@ try { ...@@ -2171,11 +2136,14 @@ try {
``` ```
### on('connectionStateChange') ### on('connectionStateChange')<sup>(deprecated)</sup>
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the HFP connection state change events. Subscribes to the HFP connection state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.on('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileonconnectionstatechange).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2183,7 +2151,7 @@ Subscribes to the HFP connection state change events. ...@@ -2183,7 +2151,7 @@ Subscribes to the HFP connection state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates an HFP connection state change event. | | type | string | Yes | Event type. The value **connectionStateChange** indicates an HFP connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the HFP connection state change event. | | callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the HFP connection state change event. |
**Example** **Example**
...@@ -2198,11 +2166,14 @@ hfpAg.on('connectionStateChange', onReceiveEvent); ...@@ -2198,11 +2166,14 @@ hfpAg.on('connectionStateChange', onReceiveEvent);
``` ```
### off('connectionStateChange') ### off('connectionStateChange')<sup>(deprecated)</sup>
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the HFP connection state change events. Unsubscribes from the HFP connection state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.off('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileoffconnectionstatechange).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2210,7 +2181,7 @@ Unsubscribes from the HFP connection state change events. ...@@ -2210,7 +2181,7 @@ Unsubscribes from the HFP connection state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates an HFP connection state change event. | | type | string | Yes | Event type. The value **connectionStateChange** indicates an HFP connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the HFP connection state change event. | | callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the HFP connection state change event. |
**Example** **Example**
...@@ -2226,7 +2197,7 @@ hfpAg.off('connectionStateChange', onReceiveEvent); ...@@ -2226,7 +2197,7 @@ hfpAg.off('connectionStateChange', onReceiveEvent);
``` ```
## HidHostProfile ## HidHostProfile<sup>(deprecated)</sup>
Before using an API of **HidHostProfile**, you need to create an instance of this class by using **getProfile()**. Before using an API of **HidHostProfile**, you need to create an instance of this class by using **getProfile()**.
...@@ -2237,6 +2208,9 @@ connect(device: string): void ...@@ -2237,6 +2208,9 @@ connect(device: string): void
Connects to the HidHost service of a device. Connects to the HidHost service of a device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [hid.HidHostProfile#connect](js-apis-bluetooth-hid.md#connect).
**System API**: This is a system API. **System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
...@@ -2272,12 +2246,15 @@ try { ...@@ -2272,12 +2246,15 @@ try {
``` ```
### disconnect<a name="HidHost-disconnect"></a> ### disconnect<sup>(deprecated)</sup><a name="HidHost-disconnect"></a>
disconnect(device: string): void disconnect(device: string): void
Disconnects from the HidHost service of a device. Disconnects from the HidHost service of a device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [hid.HidHostProfile#disconnect](js-apis-bluetooth-hid.md#disconnect).
**System API**: This is a system API. **System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
...@@ -2313,11 +2290,14 @@ try { ...@@ -2313,11 +2290,14 @@ try {
``` ```
### on('connectionStateChange') ### on('connectionStateChange')<sup>(deprecated)</sup>
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the HidHost connection state change events. Subscribes to the HidHost connection state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.on('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileonconnectionstatechange).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2339,11 +2319,14 @@ hidHost.on('connectionStateChange', onReceiveEvent); ...@@ -2339,11 +2319,14 @@ hidHost.on('connectionStateChange', onReceiveEvent);
``` ```
### off('connectionStateChange') ### off('connectionStateChange')<sup>(deprecated)</sup>
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the HidHost connection state change events. Unsubscribes from the HidHost connection state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.off('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileoffconnectionstatechange).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2370,13 +2353,19 @@ hidHost.off('connectionStateChange', onReceiveEvent); ...@@ -2370,13 +2353,19 @@ hidHost.off('connectionStateChange', onReceiveEvent);
Before using an API of **PanProfile**, you need to create an instance of this class by using **getProfile()**. Before using an API of **PanProfile**, you need to create an instance of this class by using **getProfile()**.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [pan.PanProfile](js-apis-bluetooth-pan.md#panprofile).
### disconnect<a name="PanP-disconnect"></a>
### disconnect<sup>(deprecated)</sup><a name="PanP-disconnect"></a>
disconnect(device: string): void disconnect(device: string): void
Disconnects from the Personal Area Network (PAN) service of a device. Disconnects from the Personal Area Network (PAN) service of a device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [pan.PanProfile#disconnect](js-apis-bluetooth-pan.md#disconnect).
**System API**: This is a system API. **System API**: This is a system API.
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -2412,11 +2401,14 @@ try { ...@@ -2412,11 +2401,14 @@ try {
``` ```
### on('connectionStateChange') ### on('connectionStateChange')<sup>(deprecated)</sup>
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the PAN connection state change events. Subscribes to the PAN connection state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.on('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileonconnectionstatechange).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2424,8 +2416,8 @@ Subscribes to the PAN connection state change events. ...@@ -2424,8 +2416,8 @@ Subscribes to the PAN connection state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates a PAN connection state change event. | | type | string | Yes | Event type. The value **connectionStateChange** indicates a PAN connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the PAN connection state change event. | | callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the PAN connection state change event. |
**Example** **Example**
...@@ -2438,11 +2430,14 @@ panProfile.on('connectionStateChange', onReceiveEvent); ...@@ -2438,11 +2430,14 @@ panProfile.on('connectionStateChange', onReceiveEvent);
``` ```
### off('connectionStateChange') ### off('connectionStateChange')<sup>(deprecated)</sup>
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the PAN connection state change events. Unsubscribes from the PAN connection state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.off('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileoffconnectionstatechange).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2450,8 +2445,8 @@ Unsubscribes from the PAN connection state change events. ...@@ -2450,8 +2445,8 @@ Unsubscribes from the PAN connection state change events.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- | | -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates a PAN connection state change event. | | type | string | Yes | Event type. The value **connectionStateChange** indicates a PAN connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the PAN connection state change event. | | callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the PAN connection state change event. |
**Example** **Example**
...@@ -2465,12 +2460,15 @@ panProfile.off('connectionStateChange', onReceiveEvent); ...@@ -2465,12 +2460,15 @@ panProfile.off('connectionStateChange', onReceiveEvent);
``` ```
### setTethering<a name="setTethering"></a> ### setTethering<sup>(deprecated)</sup><a name="setTethering"></a>
setTethering(enable: boolean): void setTethering(enable: boolean): void
Sets tethering. Sets tethering.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [pan.PanProfile#setTethering](js-apis-bluetooth-pan.md#setTethering).
**System API**: This is a system API. **System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
...@@ -2506,12 +2504,15 @@ try { ...@@ -2506,12 +2504,15 @@ try {
``` ```
### isTetheringOn<a name="isTetheringOn"></a> ### isTetheringOn<sup>(deprecated)</sup><a name="isTetheringOn"></a>
isTetheringOn(): boolean isTetheringOn(): boolean
Obtains the network sharing status. Obtains the network sharing status.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [pan.PanProfile#isTetheringOn](js-apis-bluetooth-pan.md#isTetheringOn).
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2538,13 +2539,19 @@ try { ...@@ -2538,13 +2539,19 @@ try {
Implements the Generic Attribute Profile (GATT) server. Before using an API of this class, you need to create a **GattServer** instance using **createGattServer()**. Implements the Generic Attribute Profile (GATT) server. Before using an API of this class, you need to create a **GattServer** instance using **createGattServer()**.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer](js-apis-bluetooth-ble.md#GattServer).
### startAdvertising ### startAdvertising<sup>(deprecated)</sup>
startAdvertising(setting: AdvertiseSetting, advData: AdvertiseData, advResponse?: AdvertiseData): void startAdvertising(setting: AdvertiseSetting, advData: AdvertiseData, advResponse?: AdvertiseData): void
Starts BLE advertising. Starts BLE advertising.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.startAdvertising](js-apis-bluetooth-ble.md#blestartadvertising).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2587,7 +2594,7 @@ let gattServer = bluetoothManager.BLE.createGattServer(); ...@@ -2587,7 +2594,7 @@ let gattServer = bluetoothManager.BLE.createGattServer();
try { try {
gattServer.startAdvertising({ gattServer.startAdvertising({
interval:150, interval:150,
txPower:60, txPower:0,
connectable:true, connectable:true,
},{ },{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"], serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
...@@ -2616,12 +2623,15 @@ try { ...@@ -2616,12 +2623,15 @@ try {
``` ```
### stopAdvertising ### stopAdvertising<sup>(deprecated)</sup>
stopAdvertising(): void stopAdvertising(): void
Stops BLE advertising. Stops BLE advertising.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.stopAdvertising](js-apis-bluetooth-ble.md#blestopadvertising).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2648,12 +2658,15 @@ try { ...@@ -2648,12 +2658,15 @@ try {
``` ```
### addService ### addService<sup>(deprecated)</sup>
addService(service: GattService): void addService(service: GattService): void
Adds a service to this GATT server. Adds a service to this GATT server.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#addService](js-apis-bluetooth-ble.md#addservice).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2710,12 +2723,15 @@ try { ...@@ -2710,12 +2723,15 @@ try {
``` ```
### removeService ### removeService<sup>(deprecated)</sup>
removeService(serviceUuid: string): void removeService(serviceUuid: string): void
Removes a service from this GATT server. Removes a service from this GATT server.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#removeService](js-apis-bluetooth-ble.md#removeservice).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2749,12 +2765,15 @@ try { ...@@ -2749,12 +2765,15 @@ try {
``` ```
### close ### close<sup>(deprecated)</sup>
close(): void close(): void
Closes this GATT server to unregister it from the protocol stack. After this method is called, this [GattServer](#gattserver) cannot be used. Closes this GATT server to unregister it from the protocol stack. After this method is called, this [GattServer](#gattserver) cannot be used.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#close](js-apis-bluetooth-ble.md#close).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2781,12 +2800,15 @@ try { ...@@ -2781,12 +2800,15 @@ try {
``` ```
### notifyCharacteristicChanged ### notifyCharacteristicChanged<sup>(deprecated)</sup>
notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic): void notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic): void
Notifies the connected client device when a characteristic value changes. Notifies the connected client device when a characteristic value changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#notifyCharacteristicChanged](js-apis-bluetooth-ble.md#notifycharacteristicchanged).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2834,12 +2856,15 @@ try { ...@@ -2834,12 +2856,15 @@ try {
``` ```
### sendResponse ### sendResponse<sup>(deprecated)</sup>
sendResponse(serverResponse: ServerResponse): void sendResponse(serverResponse: ServerResponse): void
Sends a response to a read or write request from the GATT client. Sends a response to a read or write request from the GATT client.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#sendResponse](js-apis-bluetooth-ble.md#sendresponse).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2884,12 +2909,15 @@ try { ...@@ -2884,12 +2909,15 @@ try {
``` ```
### on('characteristicRead') ### on('characteristicRead')<sup>(deprecated)</sup>
on(type: "characteristicRead", callback: Callback&lt;CharacteristicReadRequest&gt;): void on(type: "characteristicRead", callback: Callback&lt;CharacteristicReadRequest&gt;): void
Subscribes to the characteristic read request events. Subscribes to the characteristic read request events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#on('characteristicRead')](js-apis-bluetooth-ble.md#oncharacteristicread).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2927,12 +2955,15 @@ gattServer.on("characteristicRead", ReadCharacteristicReq); ...@@ -2927,12 +2955,15 @@ gattServer.on("characteristicRead", ReadCharacteristicReq);
``` ```
### off('characteristicRead') ### off('characteristicRead')<sup>(deprecated)</sup>
off(type: "characteristicRead", callback?: Callback&lt;CharacteristicReadRequest&gt;): void off(type: "characteristicRead", callback?: Callback&lt;CharacteristicReadRequest&gt;): void
Unsubscribes from the characteristic read request events. Unsubscribes from the characteristic read request events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#off('characteristicRead')](js-apis-bluetooth-ble.md#offcharacteristicread).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2952,12 +2983,15 @@ gattServer.off("characteristicRead"); ...@@ -2952,12 +2983,15 @@ gattServer.off("characteristicRead");
``` ```
### on('characteristicWrite') ### on('characteristicWrite')<sup>(deprecated)</sup>
on(type: "characteristicWrite", callback: Callback&lt;CharacteristicWriteRequest&gt;): void on(type: "characteristicWrite", callback: Callback&lt;CharacteristicWriteRequest&gt;): void
Subscribes to the characteristic write request events. Subscribes to the characteristic write request events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#on('characteristicWrite')](js-apis-bluetooth-ble.md#oncharacteristicwrite).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2998,12 +3032,15 @@ gattServer.on("characteristicWrite", WriteCharacteristicReq); ...@@ -2998,12 +3032,15 @@ gattServer.on("characteristicWrite", WriteCharacteristicReq);
``` ```
### off('characteristicWrite') ### off('characteristicWrite')<sup>(deprecated)</sup>
off(type: "characteristicWrite", callback?: Callback&lt;CharacteristicWriteRequest&gt;): void off(type: "characteristicWrite", callback?: Callback&lt;CharacteristicWriteRequest&gt;): void
Unsubscribes from the characteristic write request events. Unsubscribes from the characteristic write request events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#off('characteristicWrite')](js-apis-bluetooth-ble.md#offcharacteristicwrite).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3023,12 +3060,15 @@ gattServer.off("characteristicWrite"); ...@@ -3023,12 +3060,15 @@ gattServer.off("characteristicWrite");
``` ```
### on('descriptorRead') ### on('descriptorRead')<sup>(deprecated)</sup>
on(type: "descriptorRead", callback: Callback&lt;DescriptorReadRequest&gt;): void on(type: "descriptorRead", callback: Callback&lt;DescriptorReadRequest&gt;): void
Subscribes to the descriptor read request events. Subscribes to the descriptor read request events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#on('descriptorRead')](js-apis-bluetooth-ble.md#ondescriptorread).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3038,7 +3078,7 @@ Subscribes to the descriptor read request events. ...@@ -3038,7 +3078,7 @@ Subscribes to the descriptor read request events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------------- | | -------- | ---------------------------------------- | ---- | --------------------------------- |
| type | string | Yes | Event type. The value **descriptorRead** indicates a descriptor read request event.| | type | string | Yes | Event type. The value **descriptorRead** indicates a descriptor read request event.|
| callback | Callback&lt;[DescriptorReadRequest](#descriptorreadrequest)&gt; | Yes | Callback invoked to return a descriptor read request event from the GATT client. | | callback | Callback&lt;[DescriptorReadRequest](#descriptorreadrequest)&gt; | Yes | Callback invoked to return a descriptor read request event from the GATT client. |
**Example** **Example**
...@@ -3066,12 +3106,15 @@ gattServer.on("descriptorRead", ReadDescriptorReq); ...@@ -3066,12 +3106,15 @@ gattServer.on("descriptorRead", ReadDescriptorReq);
``` ```
### off('descriptorRead') ### off('descriptorRead')<sup>(deprecated)</sup>
off(type: "descriptorRead", callback?: Callback&lt;DescriptorReadRequest&gt;): void off(type: "descriptorRead", callback?: Callback&lt;DescriptorReadRequest&gt;): void
Unsubscribes from the descriptor read request events. Unsubscribes from the descriptor read request events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#off('descriptorRead')](js-apis-bluetooth-ble.md#offdescriptorread).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3091,12 +3134,15 @@ gattServer.off("descriptorRead"); ...@@ -3091,12 +3134,15 @@ gattServer.off("descriptorRead");
``` ```
### on('descriptorWrite') ### on('descriptorWrite')<sup>(deprecated)</sup>
on(type: "descriptorWrite", callback: Callback&lt;DescriptorWriteRequest&gt;): void on(type: "descriptorWrite", callback: Callback&lt;DescriptorWriteRequest&gt;): void
Subscribes to the descriptor write request events. Subscribes to the descriptor write request events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#on('descriptorWrite')](js-apis-bluetooth-ble.md#ondescriptorwrite).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3106,7 +3152,7 @@ Subscribes to the descriptor write request events. ...@@ -3106,7 +3152,7 @@ Subscribes to the descriptor write request events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------- |
| type | string | Yes | Event type. The value **descriptorWrite** indicates a descriptor write request event.| | type | string | Yes | Event type. The value **descriptorWrite** indicates a descriptor write request event.|
| callback | Callback&lt;[DescriptorWriteRequest](#descriptorwriterequest)&gt; | Yes | Callback invoked to return a descriptor write request from the GATT client. | | callback | Callback&lt;[DescriptorWriteRequest](#descriptorwriterequest)&gt; | Yes | Callback invoked to return a descriptor write request from the GATT client. |
**Example** **Example**
...@@ -3137,12 +3183,15 @@ gattServer.on("descriptorRead", WriteDescriptorReq); ...@@ -3137,12 +3183,15 @@ gattServer.on("descriptorRead", WriteDescriptorReq);
``` ```
### off('descriptorWrite') ### off('descriptorWrite')<sup>(deprecated)</sup>
off(type: "descriptorWrite", callback?: Callback&lt;DescriptorWriteRequest&gt;): void off(type: "descriptorWrite", callback?: Callback&lt;DescriptorWriteRequest&gt;): void
Unsubscribes from the descriptor write request events. Unsubscribes from the descriptor write request events.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#off('descriptorWrite')](js-apis-bluetooth-ble.md#offdescriptorwrite).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3162,11 +3211,14 @@ gattServer.off("descriptorWrite"); ...@@ -3162,11 +3211,14 @@ gattServer.off("descriptorWrite");
``` ```
### on('connectStateChange') ### on('connectStateChange')<sup>(deprecated)</sup>
on(type: "connectStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void on(type: "connectStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
Subscribes to the BLE connection state change events. Subscribes to the BLE connection state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#on('connectionStateChange')](js-apis-bluetooth-ble.md#onconnectionstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -3192,11 +3244,14 @@ gattServer.on("connectStateChange", Connected); ...@@ -3192,11 +3244,14 @@ gattServer.on("connectStateChange", Connected);
``` ```
### off('connectStateChange') ### off('connectStateChange')<sup>(deprecated)</sup>
off(type: "connectStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void off(type: "connectStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void
Unsubscribes from the BLE connection state change events. Unsubscribes from the BLE connection state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#off('connectionStateChange')](js-apis-bluetooth-ble.md#offconnectionstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -3221,13 +3276,19 @@ gattServer.off("connectStateChange"); ...@@ -3221,13 +3276,19 @@ gattServer.off("connectStateChange");
Implements the GATT client. Before using an API of this class, you must create a **GattClientDevice** instance using **createGattClientDevice(deviceId: string)**. Implements the GATT client. Before using an API of this class, you must create a **GattClientDevice** instance using **createGattClientDevice(deviceId: string)**.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice](js-apis-bluetooth-ble.md#gattclientdevice).
### connect
### connect<sup>(deprecated)</sup>
connect(): void connect(): void
Initiates a connection to the remote BLE device. Initiates a connection to the remote BLE device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#connect](js-apis-bluetooth-ble.md#connect).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3254,12 +3315,15 @@ try { ...@@ -3254,12 +3315,15 @@ try {
``` ```
### disconnect ### disconnect<sup>(deprecated)</sup>
disconnect(): void disconnect(): void
Disconnects from the remote BLE device. Disconnects from the remote BLE device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#disconnect](js-apis-bluetooth-ble.md#disconnect).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3286,12 +3350,15 @@ try { ...@@ -3286,12 +3350,15 @@ try {
``` ```
### close ### close<sup>(deprecated)</sup>
close(): void close(): void
Closes this GATT client to unregister it from the protocol stack. After this method is called, this [GattClientDevice](#gattclientdevice) instance cannot be used. Closes this GATT client to unregister it from the protocol stack. After this method is called, this [GattClientDevice](#gattclientdevice) instance cannot be used.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#close](js-apis-bluetooth-ble.md#close).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3320,12 +3387,15 @@ try { ...@@ -3320,12 +3387,15 @@ try {
### getServices ### getServices<sup>(deprecated)</sup>
getServices(callback: AsyncCallback&lt;Array&lt;GattService&gt;&gt;): void getServices(callback: AsyncCallback&lt;Array&lt;GattService&gt;&gt;): void
Obtains all services of the remote BLE device. This API uses an asynchronous callback to return the result. Obtains all services of the remote BLE device. This API uses an asynchronous callback to return the result.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#getServices](js-apis-bluetooth-ble.md#getservices).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3371,12 +3441,15 @@ try { ...@@ -3371,12 +3441,15 @@ try {
``` ```
### getServices ### getServices<sup>(deprecated)</sup>
getServices(): Promise&lt;Array&lt;GattService&gt;&gt; getServices(): Promise&lt;Array&lt;GattService&gt;&gt;
Obtains all services of the remote BLE device. This API uses a promise to return the result. Obtains all services of the remote BLE device. This API uses a promise to return the result.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#getServices](js-apis-bluetooth-ble.md#getservices-1).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3412,12 +3485,15 @@ try { ...@@ -3412,12 +3485,15 @@ try {
``` ```
### readCharacteristicValue ### readCharacteristicValue<sup>(deprecated)</sup>
readCharacteristicValue(characteristic: BLECharacteristic, callback: AsyncCallback&lt;BLECharacteristic&gt;): void readCharacteristicValue(characteristic: BLECharacteristic, callback: AsyncCallback&lt;BLECharacteristic&gt;): void
Reads the characteristic value of the specific service of the remote BLE device. This API uses an asynchronous callback to return the result. Reads the characteristic value of the specific service of the remote BLE device. This API uses an asynchronous callback to return the result.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#readCharacteristicValue](js-apis-bluetooth-ble.md#readcharacteristicvalue).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3476,12 +3552,15 @@ try { ...@@ -3476,12 +3552,15 @@ try {
``` ```
### readCharacteristicValue ### readCharacteristicValue<sup>(deprecated)</sup>
readCharacteristicValue(characteristic: BLECharacteristic): Promise&lt;BLECharacteristic&gt; readCharacteristicValue(characteristic: BLECharacteristic): Promise&lt;BLECharacteristic&gt;
Reads the characteristic value of the specific service of the remote BLE device. This API uses an asynchronous callback to return the result. Reads the characteristic value of the specific service of the remote BLE device. This API uses an asynchronous callback to return the result.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#readCharacteristicValue](js-apis-bluetooth-ble.md#readcharacteristicvalue-1).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3536,12 +3615,15 @@ try { ...@@ -3536,12 +3615,15 @@ try {
``` ```
### readDescriptorValue ### readDescriptorValue<sup>(deprecated)</sup>
readDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback&lt;BLEDescriptor&gt;): void readDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback&lt;BLEDescriptor&gt;): void
Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses an asynchronous callback to return the result. Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses an asynchronous callback to return the result.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#readDescriptorValue](js-apis-bluetooth-ble.md#readdescriptorvalue).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3593,12 +3675,15 @@ try { ...@@ -3593,12 +3675,15 @@ try {
``` ```
### readDescriptorValue ### readDescriptorValue<sup>(deprecated)</sup>
readDescriptorValue(descriptor: BLEDescriptor): Promise&lt;BLEDescriptor&gt; readDescriptorValue(descriptor: BLEDescriptor): Promise&lt;BLEDescriptor&gt;
Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses an asynchronous callback to return the result. Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses an asynchronous callback to return the result.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#readDescriptorValue](js-apis-bluetooth-ble.md#readdescriptorvalue-1).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3646,12 +3731,15 @@ try { ...@@ -3646,12 +3731,15 @@ try {
``` ```
### writeCharacteristicValue ### writeCharacteristicValue<sup>(deprecated)</sup>
writeCharacteristicValue(characteristic: BLECharacteristic): void writeCharacteristicValue(characteristic: BLECharacteristic): void
Writes a characteristic value to the remote BLE device. Writes a characteristic value to the remote BLE device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#writeCharacteristicValue](js-apis-bluetooth-ble.md#writecharacteristicvalue).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3699,12 +3787,15 @@ try { ...@@ -3699,12 +3787,15 @@ try {
``` ```
### writeDescriptorValue ### writeDescriptorValue<sup>(deprecated)</sup>
writeDescriptorValue(descriptor: BLEDescriptor): void writeDescriptorValue(descriptor: BLEDescriptor): void
Writes binary data to the specific descriptor of the remote BLE device. Writes binary data to the specific descriptor of the remote BLE device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#writeCharacteristicValue](js-apis-bluetooth-ble.md#writecharacteristicvalue-1).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3747,12 +3838,15 @@ try { ...@@ -3747,12 +3838,15 @@ try {
``` ```
### setBLEMtuSize ### setBLEMtuSize<sup>(deprecated)</sup>
setBLEMtuSize(mtu: number): void setBLEMtuSize(mtu: number): void
Sets the maximum transmission unit (MTU) that can be transmitted between the GATT client and its remote BLE device. This API can be used only after a connection is set up by calling [connect](#connect). Sets the maximum transmission unit (MTU) that can be transmitted between the GATT client and its remote BLE device. This API can be used only after a connection is set up by calling [connect](#connect).
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#setBLEMtuSize](js-apis-bluetooth-ble.md#setBLEMtuSize).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3784,12 +3878,15 @@ try { ...@@ -3784,12 +3878,15 @@ try {
``` ```
### setNotifyCharacteristicChanged ### setNotifyCharacteristicChanged<sup>(deprecated)</sup>
setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolean): void setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolean): void
Sets the function of notifying the GATT client when the characteristic value of the remote BLE device changes. Sets the function of notifying the GATT client when the characteristic value of the remote BLE device changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#setCharacteristicChangeNotification](js-apis-bluetooth-ble.md#setcharacteristicchangenotification).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3835,11 +3932,14 @@ try { ...@@ -3835,11 +3932,14 @@ try {
``` ```
### on('BLECharacteristicChange') ### on('BLECharacteristicChange')<sup>(deprecated)</sup>
on(type: "BLECharacteristicChange", callback: Callback&lt;BLECharacteristic&gt;): void on(type: "BLECharacteristicChange", callback: Callback&lt;BLECharacteristic&gt;): void
Subscribes to the BLE characteristic change events. The client can receive a notification from the server only after the **setNotifyCharacteristicChanged** method is called. Subscribes to the BLE characteristic changes. The client can receive a notification from the server only after the **setNotifyCharacteristicChanged** method is called.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#on('BLECharacteristicChange')](js-apis-bluetooth-ble.md#onblecharacteristicchange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -3869,11 +3969,14 @@ try { ...@@ -3869,11 +3969,14 @@ try {
``` ```
### off('BLECharacteristicChange') ### off('BLECharacteristicChange')<sup>(deprecated)</sup>
off(type: "BLECharacteristicChange", callback?: Callback&lt;BLECharacteristic&gt;): void off(type: "BLECharacteristicChange", callback?: Callback&lt;BLECharacteristic&gt;): void
Unsubscribes from the BLE characteristic change events. Unsubscribes from the BLE characteristic changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#off('BLECharacteristicChange')](js-apis-bluetooth-ble.md#offblecharacteristicchange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -3898,11 +4001,14 @@ try { ...@@ -3898,11 +4001,14 @@ try {
``` ```
### on('BLEConnectionStateChange') ### on('BLEConnectionStateChange')<sup>(deprecated)</sup>
on(type: "BLEConnectionStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void on(type: "BLEConnectionStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
Subscribes to the BLE connection state change events. Subscribes to the BLE connection state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#on('BLEConnectionStateChange')](js-apis-bluetooth-ble.md#onbleconnectionstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -3931,11 +4037,14 @@ try { ...@@ -3931,11 +4037,14 @@ try {
``` ```
### off('BLEConnectionStateChange') ### off('BLEConnectionStateChange')<sup>(deprecated)</sup>
off(type: "BLEConnectionStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void off(type: "BLEConnectionStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void
Unsubscribes from the BLE connection state change events. Unsubscribes from the BLE connection state changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#off('BLEConnectionStateChange')](js-apis-bluetooth-ble.md#offbleconnectionstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -3960,12 +4069,15 @@ try { ...@@ -3960,12 +4069,15 @@ try {
``` ```
### getDeviceName ### getDeviceName<sup>(deprecated)</sup>
getDeviceName(callback: AsyncCallback&lt;string&gt;): void getDeviceName(callback: AsyncCallback&lt;string&gt;): void
Obtains the name of the remote BLE device. This API uses an asynchronous callback to return the result. Obtains the name of the remote BLE device. This API uses an asynchronous callback to return the result.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#getDeviceName](js-apis-bluetooth-ble.md#getdevicename).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -4002,12 +4114,15 @@ try { ...@@ -4002,12 +4114,15 @@ try {
``` ```
### getDeviceName ### getDeviceName<sup>(deprecated)</sup>
getDeviceName(): Promise&lt;string&gt; getDeviceName(): Promise&lt;string&gt;
Obtains the name of the remote BLE device. This API uses a promise to return the result. Obtains the name of the remote BLE device. This API uses a promise to return the result.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#getDeviceName](js-apis-bluetooth-ble.md#getdevicename-1).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -4043,12 +4158,15 @@ try { ...@@ -4043,12 +4158,15 @@ try {
``` ```
### getRssiValue ### getRssiValue<sup>(deprecated)</sup>
getRssiValue(callback: AsyncCallback&lt;number&gt;): void getRssiValue(callback: AsyncCallback&lt;number&gt;): void
Obtains the received signal strength indication (RSSI) of the remote BLE device. This API uses an asynchronous callback to return the result. It can be used only after a connection is set up by calling [connect](#connect). Obtains the received signal strength indication (RSSI) of the remote BLE device. This API uses an asynchronous callback to return the result. It can be used only after a connection is set up by calling [connect](#connect).
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#getRssiValue](js-apis-bluetooth-ble.md#getrssivalue).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -4084,12 +4202,15 @@ try { ...@@ -4084,12 +4202,15 @@ try {
``` ```
### getRssiValue ### getRssiValue<sup>(deprecated)</sup>
getRssiValue(): Promise&lt;number&gt; getRssiValue(): Promise&lt;number&gt;
Obtains the RSSI of the remote BLE device. This API uses a promise to return the result. It can be used only after a connection is set up by calling [connect](#connect). Obtains the RSSI of the remote BLE device. This API uses a promise to return the result. It can be used only after a connection is set up by calling [connect](#connect).
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#getRssiValue](js-apis-bluetooth-ble.md#getrssivalue-1).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -4122,10 +4243,13 @@ try { ...@@ -4122,10 +4243,13 @@ try {
} }
``` ```
## ScanMode<a name="ScanMode"></a> ## ScanMode<sup>(deprecated)</sup><a name="ScanMode"></a>
Enumerates the scan modes. Enumerates the scan modes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.ScanMode](js-apis-bluetooth-connection.md#scanmode).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -4137,10 +4261,13 @@ Enumerates the scan modes. ...@@ -4137,10 +4261,13 @@ Enumerates the scan modes.
| SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE | 4 | General connectable and discoverable mode.| | SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE | 4 | General connectable and discoverable mode.|
| SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE | 5 | Limited connectable and discoverable mode.| | SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE | 5 | Limited connectable and discoverable mode.|
## BondState<a name="BondState"></a> ## BondState<sup>(deprecated)</sup><a name="BondState"></a>
Enumerates the pairing states. Enumerates the pairing states.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.BondState](js-apis-bluetooth-connection.md#bondstate).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -4150,10 +4277,13 @@ Enumerates the pairing states. ...@@ -4150,10 +4277,13 @@ Enumerates the pairing states.
| BOND_STATE_BONDED | 2 | Paired. | | BOND_STATE_BONDED | 2 | Paired. |
## SppOption<a name="SppOption"></a> ## SppOption<sup>(deprecated)</sup><a name="SppOption"></a>
Defines the SPP configuration parameters. Defines the SPP configuration parameters.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.SppOption](js-apis-bluetooth-socket.md#sppoptions).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4163,10 +4293,13 @@ Defines the SPP configuration parameters. ...@@ -4163,10 +4293,13 @@ Defines the SPP configuration parameters.
| type | [SppType](#spptype) | Yes | Yes | Type of the SPP link. | | type | [SppType](#spptype) | Yes | Yes | Type of the SPP link. |
## SppType<a name="SppType"></a> ## SppType<sup>(deprecated)</sup><a name="SppType"></a>
Enumerates the SPP link types. Enumerates the SPP link types.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.SppType](js-apis-bluetooth-socket.md#spptype).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -4174,10 +4307,13 @@ Enumerates the SPP link types. ...@@ -4174,10 +4307,13 @@ Enumerates the SPP link types.
| SPP_RFCOMM | 0 | Radio frequency communication (RFCOMM) link type.| | SPP_RFCOMM | 0 | Radio frequency communication (RFCOMM) link type.|
## GattService ## GattService<sup>(deprecated)</sup>
Defines the GATT service API parameters. Defines the GATT service API parameters.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattService](js-apis-bluetooth-ble.md#gattservice).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4188,10 +4324,13 @@ Defines the GATT service API parameters. ...@@ -4188,10 +4324,13 @@ Defines the GATT service API parameters.
| includeServices | Array&lt;[GattService](#gattservice)&gt; | Yes | Yes | Services on which the service depends. | | includeServices | Array&lt;[GattService](#gattservice)&gt; | Yes | Yes | Services on which the service depends. |
## BLECharacteristic ## BLECharacteristic<sup>(deprecated)</sup>
Defines the characteristic API parameters. Defines the characteristic API parameters.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.BLECharacteristic](js-apis-bluetooth-ble.md#blecharacteristic).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4200,12 +4339,14 @@ Defines the characteristic API parameters. ...@@ -4200,12 +4339,14 @@ Defines the characteristic API parameters.
| characteristicUuid | string | Yes | Yes | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.| | characteristicUuid | string | Yes | Yes | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| characteristicValue | ArrayBuffer | Yes | Yes | Binary value of the characteristic. | | characteristicValue | ArrayBuffer | Yes | Yes | Binary value of the characteristic. |
| descriptors | Array&lt;[BLEDescriptor](#bledescriptor)&gt; | Yes | Yes | List of descriptors of the characteristic. | | descriptors | Array&lt;[BLEDescriptor](#bledescriptor)&gt; | Yes | Yes | List of descriptors of the characteristic. |
| properties<sup>10+</sup> | [GattProperties](#gattproperties10) | Yes | Yes | Properties of the characteristic. |
## BLEDescriptor ## BLEDescriptor<sup>(deprecated)</sup>
Defines the descriptor API parameters.
Defines the BLE descriptor. > **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.BLEDescriptor](js-apis-bluetooth-ble.md#bledescriptor).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -4217,10 +4358,13 @@ Defines the BLE descriptor. ...@@ -4217,10 +4358,13 @@ Defines the BLE descriptor.
| descriptorValue | ArrayBuffer | Yes | Yes | Binary value of the descriptor. | | descriptorValue | ArrayBuffer | Yes | Yes | Binary value of the descriptor. |
## NotifyCharacteristic ## NotifyCharacteristic<sup>(deprecated)</sup>
Defines the parameters in the notifications sent when the server characteristic value changes. Defines the parameters in the notifications sent when the server characteristic value changes.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.NotifyCharacteristic](js-apis-bluetooth-ble.md#notifycharacteristic).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4231,10 +4375,13 @@ Defines the parameters in the notifications sent when the server characteristic ...@@ -4231,10 +4375,13 @@ Defines the parameters in the notifications sent when the server characteristic
| confirm | boolean | Yes | Yes | Whether the notification needs to be confirmed by the remote end. For a notification, set it to **true**. In this case, the remote end must confirm the receipt of the notification. For an indication, set it to **false**. In this case, the remote end does not need to confirm the receipt of the notification.| | confirm | boolean | Yes | Yes | Whether the notification needs to be confirmed by the remote end. For a notification, set it to **true**. In this case, the remote end must confirm the receipt of the notification. For an indication, set it to **false**. In this case, the remote end does not need to confirm the receipt of the notification.|
## CharacteristicReadRequest ## CharacteristicReadRequest<sup>(deprecated)</sup>
Defines the parameters of the **CharacteristicReadReq** event received by the server. Defines the parameters of the **CharacteristicReadReq** event received by the server.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.CharacteristicReadRequest](js-apis-bluetooth-ble.md#characteristicreadrequest).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4246,10 +4393,13 @@ Defines the parameters of the **CharacteristicReadReq** event received by the se ...@@ -4246,10 +4393,13 @@ Defines the parameters of the **CharacteristicReadReq** event received by the se
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.| | serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## CharacteristicWriteRequest ## CharacteristicWriteRequest<sup>(deprecated)</sup>
Defines the parameters of the **CharacteristicWriteReq** event received by the server. Defines the parameters of the **CharacteristicWriteReq** event received by the server.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.CharacteristicWriteRequest](js-apis-bluetooth-ble.md#characteristicwriterequest).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4262,10 +4412,13 @@ Defines the parameters of the **CharacteristicWriteReq** event received by the s ...@@ -4262,10 +4412,13 @@ Defines the parameters of the **CharacteristicWriteReq** event received by the s
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.| | serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## DescriptorReadRequest ## DescriptorReadRequest<sup>(deprecated)</sup>
Defines the parameters of the **DescriptorReadReq** event received by the server. Defines the parameters of the **DescriptorReadReq** event received by the server.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.DescriptorReadRequest](js-apis-bluetooth-ble.md#descriptorreadrequest).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4278,10 +4431,13 @@ Defines the parameters of the **DescriptorReadReq** event received by the server ...@@ -4278,10 +4431,13 @@ Defines the parameters of the **DescriptorReadReq** event received by the server
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.| | serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## DescriptorWriteRequest ## DescriptorWriteRequest<sup>(deprecated)</sup>
Defines the parameters of the **DescriptorWriteReq** event received by the server. Defines the parameters of the **DescriptorWriteReq** event received by the server.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.DescriptorWriteRequest](js-apis-bluetooth-ble.md#descriptorwriterequest).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4297,10 +4453,13 @@ Defines the parameters of the **DescriptorWriteReq** event received by the serve ...@@ -4297,10 +4453,13 @@ Defines the parameters of the **DescriptorWriteReq** event received by the serve
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.| | serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## ServerResponse ## ServerResponse<sup>(deprecated)</sup>
Defines the parameters of the server's response to the GATT client's read/write request. Defines the parameters of the server's response to the GATT client's read/write request.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ServerResponse](js-apis-bluetooth-ble.md#serverresponse).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4312,10 +4471,13 @@ Defines the parameters of the server's response to the GATT client's read/write ...@@ -4312,10 +4471,13 @@ Defines the parameters of the server's response to the GATT client's read/write
| value | ArrayBuffer | Yes | No | Binary data in the response. | | value | ArrayBuffer | Yes | No | Binary data in the response. |
## BLEConnectChangedState ## BLEConnectChangedState<sup>(deprecated)</sup>
Defines the parameters of **BLEConnectChangedState**. Defines the parameters of **BLEConnectChangedState**.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [BLEConnectionChangeState](js-apis-bluetooth-ble.md#bleconnectionchangestate).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
...@@ -4324,10 +4486,13 @@ Defines the parameters of **BLEConnectChangedState**. ...@@ -4324,10 +4486,13 @@ Defines the parameters of **BLEConnectChangedState**.
| state | [ProfileConnectionState](#profileconnectionstate) | Yes | Yes | BLE connection state. | | state | [ProfileConnectionState](#profileconnectionstate) | Yes | Yes | BLE connection state. |
## ProfileConnectionState ## ProfileConnectionState<sup>(deprecated)</sup>
Enumerates the profile connection states. Enumerates the profile connection states.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [constant.ProfileConnectionState](js-apis-bluetooth-constant.md#profileconnectionstate).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -4338,10 +4503,13 @@ Enumerates the profile connection states. ...@@ -4338,10 +4503,13 @@ Enumerates the profile connection states.
| STATE_DISCONNECTING | 3 | Disconnecting.| | STATE_DISCONNECTING | 3 | Disconnecting.|
## ScanFilter ## ScanFilter<sup>(deprecated)</sup>
Defines the scan filter parameters. Defines the scan filter parameters.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ScanFilter](js-apis-bluetooth-ble.md#scanfilter).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
...@@ -4359,10 +4527,13 @@ Defines the scan filter parameters. ...@@ -4359,10 +4527,13 @@ Defines the scan filter parameters.
| manufactureDataMask | ArrayBuffer | Yes | Yes | Manufacturer data mask of the device to filter, for example, **[0xFF, 0xFF, 0xFF]**.| | manufactureDataMask | ArrayBuffer | Yes | Yes | Manufacturer data mask of the device to filter, for example, **[0xFF, 0xFF, 0xFF]**.|
## ScanOptions ## ScanOptions<sup>(deprecated)</sup>
Defines the scan configuration parameters. Defines the scan configuration parameters.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ScanOptions](js-apis-bluetooth-ble.md#scanoptions).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4372,10 +4543,13 @@ Defines the scan configuration parameters. ...@@ -4372,10 +4543,13 @@ Defines the scan configuration parameters.
| matchMode | [MatchMode](#matchmode) | Yes | Yes | Hardware filtering match mode. The default value is **MATCH_MODE_AGGRESSIVE**.| | matchMode | [MatchMode](#matchmode) | Yes | Yes | Hardware filtering match mode. The default value is **MATCH_MODE_AGGRESSIVE**.|
## ScanDuty ## ScanDuty<sup>(deprecated)</sup>
Enumerates the scan duty options. Enumerates the scan duty options.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ScanDuty](js-apis-bluetooth-ble.md#scanduty).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -4385,10 +4559,13 @@ Enumerates the scan duty options. ...@@ -4385,10 +4559,13 @@ Enumerates the scan duty options.
| SCAN_MODE_LOW_LATENCY | 2 | Low-latency mode. | | SCAN_MODE_LOW_LATENCY | 2 | Low-latency mode. |
## MatchMode ## MatchMode<sup>(deprecated)</sup>
Enumerates the hardware match modes of BLE scan filters. Enumerates the hardware match modes of BLE scan filters.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.MatchMode](js-apis-bluetooth-ble.md#matchmode).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -4397,10 +4574,13 @@ Enumerates the hardware match modes of BLE scan filters. ...@@ -4397,10 +4574,13 @@ Enumerates the hardware match modes of BLE scan filters.
| MATCH_MODE_STICKY | 2 | Hardware reports the scan result with a higher threshold of signal strength and sightings. | | MATCH_MODE_STICKY | 2 | Hardware reports the scan result with a higher threshold of signal strength and sightings. |
## ScanResult ## ScanResult<sup>(deprecated)</sup>
Defines the scan result. Defines the scan result.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ScanResult](js-apis-bluetooth-ble.md#scanresult).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4408,13 +4588,15 @@ Defines the scan result. ...@@ -4408,13 +4588,15 @@ Defines the scan result.
| deviceId | string | Yes | No | Address of the scanned device, for example, XX:XX:XX:XX:XX:XX.| | deviceId | string | Yes | No | Address of the scanned device, for example, XX:XX:XX:XX:XX:XX.|
| rssi | number | Yes | No | RSSI of the device. | | rssi | number | Yes | No | RSSI of the device. |
| data | ArrayBuffer | Yes | No | Advertisement packets sent by the device. | | data | ArrayBuffer | Yes | No | Advertisement packets sent by the device. |
| deviceName<sup>10+</sup> | string | Yes | No | Name of the device detected. |
## BluetoothState ## BluetoothState<sup>(deprecated)</sup>
Enumerates the Bluetooth states. Enumerates the Bluetooth states.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [access.BluetoothState](js-apis-bluetooth-access.md#bluetoothstate).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -4428,10 +4610,13 @@ Enumerates the Bluetooth states. ...@@ -4428,10 +4610,13 @@ Enumerates the Bluetooth states.
| STATE_BLE_TURNING_OFF | 6 | The LE-only mode is being turned off for Bluetooth.| | STATE_BLE_TURNING_OFF | 6 | The LE-only mode is being turned off for Bluetooth.|
## AdvertiseSetting ## AdvertiseSetting<sup>(deprecated)</sup>
Defines the BLE advertising parameters. Defines the BLE advertising parameters.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.AdvertiseSetting](js-apis-bluetooth-ble.md#advertisesetting).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4441,10 +4626,13 @@ Defines the BLE advertising parameters. ...@@ -4441,10 +4626,13 @@ Defines the BLE advertising parameters.
| connectable | boolean | Yes | Yes | Whether the advertisement is connectable. The default value is **true**. | | connectable | boolean | Yes | Yes | Whether the advertisement is connectable. The default value is **true**. |
## AdvertiseData ## AdvertiseData<sup>(deprecated)</sup>
Defines the content of a BLE advertisement packet. Defines the content of a BLE advertisement packet.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.AdvertiseData](js-apis-bluetooth-ble.md#advertisedata).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4452,13 +4640,15 @@ Defines the content of a BLE advertisement packet. ...@@ -4452,13 +4640,15 @@ Defines the content of a BLE advertisement packet.
| serviceUuids | Array&lt;string&gt; | Yes | Yes | List of service UUIDs to broadcast.| | serviceUuids | Array&lt;string&gt; | Yes | Yes | List of service UUIDs to broadcast.|
| manufactureData | Array&lt;[ManufactureData](#manufacturedata)&gt; | Yes | Yes | List of manufacturers to broadcast. | | manufactureData | Array&lt;[ManufactureData](#manufacturedata)&gt; | Yes | Yes | List of manufacturers to broadcast. |
| serviceData | Array&lt;[ServiceData](#servicedata)&gt; | Yes | Yes | List of service data to broadcast. | | serviceData | Array&lt;[ServiceData](#servicedata)&gt; | Yes | Yes | List of service data to broadcast. |
| includeDeviceName<sup>10+</sup> | boolean | Yes | Yes | Whether the device name is contained. This parameter is optional. |
## ManufactureData ## ManufactureData<sup>(deprecated)</sup>
Defines the content of a BLE advertisement packet. Defines the content of a BLE advertisement packet.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ManufactureData](js-apis-bluetooth-ble.md#manufacturedata).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4467,10 +4657,13 @@ Defines the content of a BLE advertisement packet. ...@@ -4467,10 +4657,13 @@ Defines the content of a BLE advertisement packet.
| manufactureValue | ArrayBuffer | Yes | Yes | Manufacturer data. | | manufactureValue | ArrayBuffer | Yes | Yes | Manufacturer data. |
## ServiceData ## ServiceData<sup>(deprecated)</sup>
Defines the service data contained in an advertisement packet. Defines the service data contained in an advertisement packet.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ServiceData](js-apis-bluetooth-ble.md#servicedata).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4479,23 +4672,28 @@ Defines the service data contained in an advertisement packet. ...@@ -4479,23 +4672,28 @@ Defines the service data contained in an advertisement packet.
| serviceValue | ArrayBuffer | Yes | Yes | Service data. | | serviceValue | ArrayBuffer | Yes | Yes | Service data. |
## PinRequiredParam<a name="PinRequiredParam"></a> ## PinRequiredParam<sup>(deprecated)</sup><a name="PinRequiredParam"></a>
Defines the pairing request parameters. Defines the pairing request parameters.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.PinRequiredParam](js-apis-bluetooth-connection.md#pinrequiredparam).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------- | ------ | ---- | ---- | ----------- | | -------- | ------ | ---- | ---- | ----------- |
| deviceId | string | Yes | No | ID of the device to pair.| | deviceId | string | Yes | No | ID of the device to pair.|
| pinCode | string | Yes | No | Key for the device pairing. | | pinCode | string | Yes | No | Key for the device pairing. |
| pinType<sup>10+</sup> | [PinType](#pintype10) | Yes | No | Type of the device to pair.<br>This is a system API. |
## BondStateParam<a name="BondStateParam"></a> ## BondStateParam<sup>(deprecated)</sup><a name="BondStateParam"></a>
Defines the pairing state parameters. Defines the pairing state parameters.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.BondStateParam](js-apis-bluetooth-connection.md#bondstateparam).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4504,10 +4702,13 @@ Defines the pairing state parameters. ...@@ -4504,10 +4702,13 @@ Defines the pairing state parameters.
| state | BondState | Yes | No | State of the device.| | state | BondState | Yes | No | State of the device.|
## StateChangeParam<a name="StateChangeParam"></a> ## StateChangeParam<sup>(deprecated)</sup><a name="StateChangeParam"></a>
Defines the profile state change parameters. Defines the profile state change parameters.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.StateChangeParam](js-apis-bluetooth-baseProfile.md#statechangeparam).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
...@@ -4516,25 +4717,13 @@ Defines the profile state change parameters. ...@@ -4516,25 +4717,13 @@ Defines the profile state change parameters.
| state | [ProfileConnectionState](#profileconnectionstate) | Yes | No | Profile connection state of the device.| | state | [ProfileConnectionState](#profileconnectionstate) | Yes | No | Profile connection state of the device.|
## GattProperties<sup>10+</sup><a name="GattProperties"></a> ## DeviceClass<sup>(deprecated)</sup><a name="DeviceClass"></a>
Defines the properties of a GATT characteristic.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Mandatory | Description |
| -------- | ------ |---- | ----------- |
| write<sup>10+</sup> | boolean | Yes | Permits writes of the characteristic value (with a response).|
| writeNoResponse<sup>10+</sup> | boolean | Yes | Permits writes of the characteristic value (without a response).|
| read<sup>10+</sup> | boolean | Yes | Permits reads of the characteristic value.|
| notify<sup>10+</sup> | boolean | Yes | Permits notifications of the characteristic value.|
| indicate<sup>10+</sup> | boolean | Yes | Permits notifications of the characteristic value without acknowledgement.|
## DeviceClass<a name="DeviceClass"></a>
Defines the class of a Bluetooth device. Defines the class of a Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.DeviceClass](js-apis-bluetooth-connection.md#deviceclass).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -4544,10 +4733,13 @@ Defines the class of a Bluetooth device. ...@@ -4544,10 +4733,13 @@ Defines the class of a Bluetooth device.
| classOfDevice | number | Yes | No | Class of the device. | | classOfDevice | number | Yes | No | Class of the device. |
## MajorClass<a name="MajorClass"></a> ## MajorClass<sup>(deprecated)</sup><a name="MajorClass"></a>
Enumerates the major classes of Bluetooth devices. Enumerates the major classes of Bluetooth devices.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [constant.MajorClass](js-apis-bluetooth-constant.md#majorclass).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -4565,10 +4757,13 @@ Enumerates the major classes of Bluetooth devices. ...@@ -4565,10 +4757,13 @@ Enumerates the major classes of Bluetooth devices.
| MAJOR_UNCATEGORIZED | 0x1F00 | Unclassified device. | | MAJOR_UNCATEGORIZED | 0x1F00 | Unclassified device. |
## MajorMinorClass<a name="MajorMinorClass"></a> ## MajorMinorClass<sup>(deprecated)</sup><a name="MajorMinorClass"></a>
Enumerates the major and minor classes of Bluetooth devices. Enumerates the major and minor classes of Bluetooth devices.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [constant.MajorMinorClass](js-apis-bluetooth-constant.md#majorminorclass).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -4661,10 +4856,13 @@ Enumerates the major and minor classes of Bluetooth devices. ...@@ -4661,10 +4856,13 @@ Enumerates the major and minor classes of Bluetooth devices.
| HEALTH_PERSONAL_MOBILITY_DEVICE | 0x093C | Personal mobility device. | | HEALTH_PERSONAL_MOBILITY_DEVICE | 0x093C | Personal mobility device. |
## PlayingState<a name="PlayingState"></a> ## PlayingState<sup>(deprecated)</sup><a name="PlayingState"></a>
Enumerates the A2DP playing states. Enumerates the A2DP playing states.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [a2dp.PlayingState](js-apis-bluetooth-a2dp.md#playingstate).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -4673,10 +4871,13 @@ Enumerates the A2DP playing states. ...@@ -4673,10 +4871,13 @@ Enumerates the A2DP playing states.
| STATE_PLAYING | 0x0001 | Playing.| | STATE_PLAYING | 0x0001 | Playing.|
## ProfileId<a name="ProfileId"></a> ## ProfileId<sup>(deprecated)</sup><a name="ProfileId"></a>
Enumerates the Bluetooth profiles. API version 9 is added with **PROFILE_HID_HOST** and **PROFILE_PAN_NETWORK**. Enumerates the Bluetooth profiles. API version 9 is added with **PROFILE_HID_HOST** and **PROFILE_PAN_NETWORK**.
> **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [constant.ProfileId](js-apis-bluetooth-constant.md#profileid).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -4685,35 +4886,3 @@ Enumerates the Bluetooth profiles. API version 9 is added with **PROFILE_HID_HOS ...@@ -4685,35 +4886,3 @@ Enumerates the Bluetooth profiles. API version 9 is added with **PROFILE_HID_HOS
| PROFILE_HANDS_FREE_AUDIO_GATEWAY | 4 | HFP profile. | | PROFILE_HANDS_FREE_AUDIO_GATEWAY | 4 | HFP profile. |
| PROFILE_HID_HOST | 6 | Human Interface Device (HID) profile. | | PROFILE_HID_HOST | 6 | Human Interface Device (HID) profile. |
| PROFILE_PAN_NETWORK | 7 | PAN profile. | | PROFILE_PAN_NETWORK | 7 | PAN profile. |
## BluetoothTransport<sup>10+</sup><a name="BluetoothTransport"></a>
Enumerates the device types. The default device type is **TRANSPORT_BR_EDR**.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| -------------------------------- | ------ | --------------- |
| TRANSPORT_BR_EDR<sup>10+</sup> | 0 | Classic Bluetooth (BR/EDR) device.|
| TRANSPORT_LE<sup>10+</sup> | 1 | BLE device. |
## PinType<sup>10+</sup><a name="PinType"></a>
Enumerates the Bluetooth pairing types.
**System API**: This is a system API.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| -------------------------------- | ------ | --------------- |
| PIN_TYPE_ENTER_PIN_CODE<sup>10+</sup> | 0 | The user needs to enter the PIN displayed on the peer device.<br>This is a system API.|
| PIN_TYPE_ENTER_PASSKEY<sup>10+</sup> | 1 | The user needs to enter the PASSKEY displayed on the peer device.<br>This is a system API. |
| PIN_TYPE_CONFIRM_PASSKEY<sup>10+</sup> | 2 | The user needs to confirm the PASSKEY displayed on the local device.<br>This is a system API. |
| PIN_TYPE_NO_PASSKEY_CONSENT<sup>10+</sup> | 3 | There is no PASSKEY, and the user needs to accept or reject the pairing request.<br>This is a system API. |
| PIN_TYPE_NOTIFY_PASSKEY<sup>10+</sup> | 4 | The user needs to enter the PASSKEY displayed on the local device on the peer device.<br>This is a system API. |
| PIN_TYPE_DISPLAY_PIN_CODE<sup>10+</sup> | 5 | The user needs to enter the PIN displayed on the peer device for Bluetooth 2.0 devices.<br>This is a system API. |
| PIN_TYPE_OOB_CONSENT<sup>10+</sup> | 6 | The user needs to accept or reject the out of band (OOB) pairing request.<br>This is a system API. |
| PIN_TYPE_PIN_16_DIGITS<sup>10+</sup> | 7 | The user needs to enter the 16-digit PIN displayed on the peer device.<br>This is a system API. |
# @ohos.resourceschedule.deviceStandby (Device Standby)
A device enters standby mode if it is unused for a long period of time or after the Power button is pressed. The standby mode prolongs the battery life without affecting the use of applications. The **deviceStandby** module provides APIs for you to check whether a device is in standby mode and request or cancel standby resource control for an application.
> **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.
## Modules to Import
```js
import deviceStandby from '@ohos.resourceschedule.deviceStandby';
```
## deviceStandby.getExemptedApps
getExemptedApps(resourceTypes: number, callback: AsyncCallback<Array&lt;ExemptedAppInfo&gt;>): void;
Obtains the list of applications that can still use resources of the specified types when the device is in standby mode. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
**Required permissions**: ohos.permission.DEVICE_STANDBY_EXEMPTION
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ------------------------------ |
| [ResourceTypes](#resourcetype)|number | Yes | Types of resources that can be used.|
| callback | AsyncCallback<Array&lt;[ExemptedAppInfo](#exemptedappinfo)&gt;> | Yes |Callback used to return the exempted application information.|
**Error codes**
For details about the error codes, see [Background Task Management Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
| ID | Error Message |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
| 9800003 | Inner transact failed. |
| 9800004 | System service operation failed. |
| 18700001 | Caller information verification failed. |
**Example**
```js
try{
deviceStandby.getExemptedApps(resourceTypes, (err, res) => {
if (err) {
console.log('DEVICE_STANDBY getExemptedApps callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('DEVICE_STANDBY getExemptedApps callback success.');
for (let i = 0; i < res.length; i++) {
console.log('DEVICE_STANDBY getExemptedApps callback result ' + JSON.stringify(res[i]));
}
}
});
} catch (error) {
console.log('DEVICE_STANDBY getExemptedApps throw error, code is: ' + error.code + ',message is: ' + error.message);
}
```
## deviceStandby.getExemptedApps
getExemptedApps(resourceTypes: number): Promise<Array&lt;ExemptedAppInfo&gt;>;
Obtains the list of applications that can still use resources of the specified types when the device is in standby mode. This API uses a promise to return the result.
**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
**Required permissions**: ohos.permission.DEVICE_STANDBY_EXEMPTION
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ------------------------------ |
| [ResourceTypes](#resourcetype)|number | Yes |Types of resources that can be used.|
**Return value**
| Type | Description |
| --------------------- | ---------------------------------------- |
| Promise<Array&lt;[ExemptedAppInfo](#exemptedappinfo)&gt;> | Promise used to return the exempted application information.|
**Error codes**
For details about the error codes, see [Background Task Management Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
| ID | Error Message |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
| 9800003 | Inner transact failed. |
| 9800004 | System service operation failed. |
| 18700001 | Caller information verification failed. |
**Example**
```js
try{
deviceStandby.getExemptedApps(resourceTypes).then( res => {
console.log('DEVICE_STANDBY getExemptedApps promise success.');
for (let i = 0; i < res.length; i++) {
console.log('DEVICE_STANDBY getExemptedApps promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('DEVICE_STANDBY getExemptedApps promise failed. code is: ' + err.code + ',message is: ' + err.message);
});
} catch (error) {
console.log('DEVICE_STANDBY getExemptedApps throw error, code is: ' + error.code + ',message is: ' + error.message);
}
```
## deviceStandby.requestExemptionResource
requestExemptionResource(request: ResourceRequest): void;
Requests exemption, so that the application can use restricted resources when the device is in standby mode.
**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
**Required permissions**: ohos.permission.DEVICE_STANDBY_EXEMPTION
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ------------------------------ |
| request |[ResourceRequest](#resourcerequest)| Yes | Request body.|
**Error codes**
For details about the error codes, see [Background Task Management Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
| ID | Error Message |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
| 9800003 | Inner transact failed. |
| 9800004 | System service operation failed. |
| 18700001 | Caller information verification failed. |
**Example**
```js
let resRequest = {
resourceTypes: 1,
uid:10003,
name:"com.example.app",
duration:10,
reason:"apply",
};
// Promise mode
try{
deviceStandby.requestExemptionResource(resRequest).then( () => {
console.log('DEVICE_STANDBY requestExemptionResource promise succeeded.');
}).catch( err => {
console.log('DEVICE_STANDBY requestExemptionResource promise failed. code is: ' + err.code + ',message is: ' + err.message);
});
} catch (error) {
console.log('DEVICE_STANDBY requestExemptionResource throw error, code is: ' + error.code + ',message is: ' + error.message);
}
// Asynchronous callback mode
try{
deviceStandby.requestExemptionResource(resRequest, (err) => {
if (err) {
console.log('DEVICE_STANDBY requestExemptionResource callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('DEVICE_STANDBY requestExemptionResource callback succeeded.');
}
});
} catch (error) {
console.log('DEVICE_STANDBY requestExemptionResource throw error, code is: ' + error.code + ',message is: ' + error.message);
}
```
## deviceStandby.releaseExemptionResource
releaseExemptionResource(request: ResourceRequest): void;
Cancels exemption for the application.
**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
**Required permissions**: ohos.permission.DEVICE_STANDBY_EXEMPTION
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ------------------------------ |
| request |[ResourceRequest](#resourcerequest)| Yes | Request body.|
**Error codes**
For details about the error codes, see [Background Task Management Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
| ID | Error Message |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
| 9800003 | Inner transact failed. |
| 9800004 | System service operation failed. |
| 18700001 | Caller information verification failed. |
**Example**
```js
let resRequest = {
resourceTypes: 1,
uid:10003,
name:"com.demo.app",
duration:10,
reason:"unapply",
};
// Promise mode
try{
deviceStandby.releaseExemptionResource(resRequest).then( () => {
console.log('DEVICE_STANDBY releaseExemptionResource promise succeeded.');
}).catch( err => {
console.log('DEVICE_STANDBY releaseExemptionResource promise failed. code is: ' + err.code + ',message is: ' + err.message);
});
} catch (error) {
console.log('DEVICE_STANDBY releaseExemptionResource throw error, code is: ' + error.code + ',message is: ' + error.message);
}
// Asynchronous callback mode
try{
deviceStandby.releaseExemptionResource(resRequest, (err) => {
if (err) {
console.log('DEVICE_STANDBY releaseExemptionResource callback failed. code is: ' + err.code + ',message is: ' + err.message);
} else {
console.log('DEVICE_STANDBY releaseExemptionResource callback succeeded.');
}
});
} catch (error) {
console.log('DEVICE_STANDBY releaseExemptionResource throw error, code is: ' + error.code + ',message is: ' + error.message);
}
```
## ResourceType
Enumerates the types of resources that can be used by exempted applications.
**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
**System API**: This is a system API.
|Name |Value |Description|
| ------------ | ------------ |--------------|
|NETWORK |1 |Network access resource.|
|RUNNING_LOCK |2 |CPU running lock resource.|
|TIMER |4 | Timer task resource.|
|WORK_SCHEDULER |8 | Work task resource.|
|AUTO_SYNC |16 | Automatic synchronization resource.|
|PUSH |32 | Push kit resource.|
|FREEZE |64 | Freezing application resource.|
## ExemptedAppInfo
Defines the information about an exempted application.
**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
**System API**: This is a system API.
|Name |Type | Mandatory |Description |
| ------------ | ------------ |------------ | ------------ |
|[resourceTypes](#resourcetype) | number | Yes |Types of resources that can be used. |
|name |string | Yes | Name of the application. |
|duration | number | Yes | Exemption duration.|
## ResourceRequest
Defines the message used to request to be an exempted application.
**System capability**: SystemCapability.ResourceSchedule.DeviceStandby
**System API**: This is a system API.
|Name |Type | Mandatory |Description |
| ------------ | ------------ |------------| ------------ |
|[resourceTypes](#resourcetype) | number | Yes |Types of resources that can be used. |
|uid | number | Yes |UID of the application. |
|name |string | Yes | Name of the application. |
|duration | number | Yes | Exemption duration.|
|reason |string | Yes | Reason for the request. |
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
- Quick Start - Quick Start
- Getting Started - Getting Started
- [Before You Start](quick-start/start-overview.md) - [Before You Start](quick-start/start-overview.md)
- [Getting Started with ArkTS in Stage Model](quick-start/start-with-ets-stage.md) - [Building the First ArkTS Application in Stage Model](quick-start/start-with-ets-stage.md)
- Development Fundamentals - Development Fundamentals
- Application Package Fundamentals - Application Package Fundamentals
- [Application Package Overview](quick-start/application-package-overview.md) - [Application Package Overview](quick-start/application-package-overview.md)
...@@ -43,8 +43,8 @@ ...@@ -43,8 +43,8 @@
- [Resource Categories and Access](quick-start/resource-categories-and-access.md) - [Resource Categories and Access](quick-start/resource-categories-and-access.md)
- Learning ArkTS - Learning ArkTS
- [Getting Started with ArkTS](quick-start/arkts-get-started.md) - [Getting Started with ArkTS](quick-start/arkts-get-started.md)
- [Introduction to ArkTS]quick-start/arkts/introduction-to-arkts.md) - [Introduction to ArkTS](quick-start/introduction-to-arkts.md)
- [TypeScript to ArkTS Migration](quick-start/arkts/typescript-to-arkts-migration-guide.md) - [TypeScript to ArkTS Migration](quick-start/typescript-to-arkts-migration-guide.md)
- UI Paradigm - UI Paradigm
- Basic Syntax - Basic Syntax
- [Basic Syntax Overview](quick-start/arkts-basic-syntax-overview.md) - [Basic Syntax Overview](quick-start/arkts-basic-syntax-overview.md)
...@@ -147,7 +147,6 @@ ...@@ -147,7 +147,6 @@
- [Cross-Device Migration (for System Applications Only)](application-models/hop-cross-device-migration.md) - [Cross-Device Migration (for System Applications Only)](application-models/hop-cross-device-migration.md)
- [Multi-device Collaboration (for System Applications Only)](application-models/hop-multi-device-collaboration.md) - [Multi-device Collaboration (for System Applications Only)](application-models/hop-multi-device-collaboration.md)
- [Subscribing to System Environment Variable Changes](application-models/subscribe-system-environment-variable-changes.md) - [Subscribing to System Environment Variable Changes](application-models/subscribe-system-environment-variable-changes.md)
- [Setting Atomic Services to Support Sharing](application-models/atomic-services-support-sharing.md)
- Process Model - Process Model
- [Process Model Overview](application-models/process-model-stage.md) - [Process Model Overview](application-models/process-model-stage.md)
- Common Events - Common Events
...@@ -289,14 +288,26 @@ ...@@ -289,14 +288,26 @@
- [Drawing Geometric Shapes (Shape)](ui/arkts-geometric-shape-drawing.md) - [Drawing Geometric Shapes (Shape)](ui/arkts-geometric-shape-drawing.md)
- [Drawing Custom Graphics on the Canvas (Canvas)](ui/arkts-drawing-customization-on-canvas.md) - [Drawing Custom Graphics on the Canvas (Canvas)](ui/arkts-drawing-customization-on-canvas.md)
- Using Animation - Using Animation
- [Animation Overview](ui/arkts-animation-overview.md) - [Animation Overview](ui/arkts-animation.md)
- Animation Within a Page - Property Animation
- [Layout Update Animation](ui/arkts-layout-update-animation.md) - [Property Animation Overview](ui/arkts-attribute-animation-overview.md)
- [Transition Animation Within a Component](ui/arkts-transition-animation-within-component.md) - [Property Animation APIs](ui/arkts-attribute-animation-apis.md)
- [Spring Curve Animation](ui/arkts-spring-animation.md) - [Custom Property Animation](ui/arkts-custom-attribute-animation.md)
- Animation Between Pages - Transition Animation
- [Zoom Animation](ui/arkts-zoom-animation.md) - [Transition Animation Overview](ui/arkts-transition-overview.md)
- [Page Transition Animation](ui/arkts-page-transition-animation.md) - [Enter/Exit Transition](ui/arkts-enter-exit-transition.md)
- [Navigation Transition](ui/arkts-navigation-transition.md)
- [Modal Transition](ui/arkts-modal-transition.md)
- [Shared Element Transition](ui/arkts-shared-element-transition.md)
- [Component Animation](ui/arkts-component-animation.md)
- Animation Curve
- [Traditional Curve](ui/arkts-traditional-curve.md)
- [Spring Curve](ui/arkts-spring-curve.md)
- [Animation Smoothing](ui/arkts-animation-smoothing.md)
- Animation Effects
- [Blur Effect](ui/arkts-blur-effect.md)
- [Shadow Effect](ui/arkts-shadow-effect.md)
- [Color Effect](ui/arkts-color-effect.md)
- Using Interaction Events - Using Interaction Events
- [Interaction Event Overview](ui/arkts-event-overview.md) - [Interaction Event Overview](ui/arkts-event-overview.md)
- Universal Events - Universal Events
...@@ -544,6 +555,7 @@ ...@@ -544,6 +555,7 @@
- [Ethernet Connection](connectivity/net-ethernet.md) - [Ethernet Connection](connectivity/net-ethernet.md)
- [Network Connection Management](connectivity/net-connection-manager.md) - [Network Connection Management](connectivity/net-connection-manager.md)
- [MDNS Management](connectivity/net-mdns.md) - [MDNS Management](connectivity/net-mdns.md)
- [Traffic Management](connectivity/net-statistics.md)
- IPC & RPC - IPC & RPC
- [IPC & RPC Overview](connectivity/ipc-rpc-overview.md) - [IPC & RPC Overview](connectivity/ipc-rpc-overview.md)
- [IPC & RPC Development](connectivity/ipc-rpc-development-guideline.md) - [IPC & RPC Development](connectivity/ipc-rpc-development-guideline.md)
...@@ -574,7 +586,7 @@ ...@@ -574,7 +586,7 @@
- [Unified Data Definition](database/unified-data-definition.md) - [Unified Data Definition](database/unified-data-definition.md)
- One-to-Many Data Sharing (for System Applications Only) - One-to-Many Data Sharing (for System Applications Only)
- [Sharing Data Using DataShareExtensionAbility](database/share-data-by-datashareextensionability.md) - [Sharing Data Using DataShareExtensionAbility](database/share-data-by-datashareextensionability.md)
- [Data Sharing Through Silent Access](database/share-data-by-silent-access.md) - [Silent Access via the DatamgrService](database/share-data-by-silent-access.md)
- Many-to-Many Data Sharing - Many-to-Many Data Sharing
- [Sharing Data via Unified Data Channels](database/unified-data-channels.md) - [Sharing Data via Unified Data Channels](database/unified-data-channels.md)
- File Management - File Management
...@@ -896,7 +908,6 @@ ...@@ -896,7 +908,6 @@
- [@ohos.arkui.drawableDescriptor (DrawableDescriptor)](reference/apis/js-apis-arkui-drawableDescriptor.md) - [@ohos.arkui.drawableDescriptor (DrawableDescriptor)](reference/apis/js-apis-arkui-drawableDescriptor.md)
- [@ohos.arkui.inspector (Layout Callback)](reference/apis/js-apis-arkui-inspector.md) - [@ohos.arkui.inspector (Layout Callback)](reference/apis/js-apis-arkui-inspector.md)
- [@ohos.arkui.UIContext (UIContext)](reference/apis/js-apis-arkui-UIContext.md) - [@ohos.arkui.UIContext (UIContext)](reference/apis/js-apis-arkui-UIContext.md)
- [@ohos.componentUtils (componentUtils)](reference/apis/js-apis-componentUtils.md)
- [@ohos.curves (Interpolation Calculation)](reference/apis/js-apis-curve.md) - [@ohos.curves (Interpolation Calculation)](reference/apis/js-apis-curve.md)
- [@ohos.font (Custom Font Registration)](reference/apis/js-apis-font.md) - [@ohos.font (Custom Font Registration)](reference/apis/js-apis-font.md)
- [@ohos.matrix4 (Matrix Transformation)](reference/apis/js-apis-matrix4.md) - [@ohos.matrix4 (Matrix Transformation)](reference/apis/js-apis-matrix4.md)
...@@ -994,6 +1005,7 @@ ...@@ -994,6 +1005,7 @@
- [@ohos.net.connection (Network Connection Management)](reference/apis/js-apis-net-connection.md) - [@ohos.net.connection (Network Connection Management)](reference/apis/js-apis-net-connection.md)
- [@ohos.net.ethernet (Ethernet Connection Management)](reference/apis/js-apis-net-ethernet.md) - [@ohos.net.ethernet (Ethernet Connection Management)](reference/apis/js-apis-net-ethernet.md)
- [@ohos.net.http (Data Request)](reference/apis/js-apis-http.md) - [@ohos.net.http (Data Request)](reference/apis/js-apis-http.md)
- [@ohos.net.policy (Network Policy Management)](reference/apis/js-apis-net-policy.md)
- [@ohos.net.mdns (mDNS Management)](reference/apis/js-apis-net-mdns.md) - [@ohos.net.mdns (mDNS Management)](reference/apis/js-apis-net-mdns.md)
- [@ohos.net.sharing (Network Sharing)](reference/apis/js-apis-net-sharing.md) - [@ohos.net.sharing (Network Sharing)](reference/apis/js-apis-net-sharing.md)
- [@ohos.net.socket (Socket Connection)](reference/apis/js-apis-socket.md) - [@ohos.net.socket (Socket Connection)](reference/apis/js-apis-socket.md)
...@@ -1058,6 +1070,7 @@ ...@@ -1058,6 +1070,7 @@
- [@ohos.cooperate (Screen Hopping)](reference/apis/js-apis-devicestatus-cooperate.md) - [@ohos.cooperate (Screen Hopping)](reference/apis/js-apis-devicestatus-cooperate.md)
- [@ohos.deviceAttest (Device Attestation)](reference/apis/js-apis-deviceAttest.md) - [@ohos.deviceAttest (Device Attestation)](reference/apis/js-apis-deviceAttest.md)
- [@ohos.deviceInfo (Device Information)](reference/apis/js-apis-device-info.md) - [@ohos.deviceInfo (Device Information)](reference/apis/js-apis-device-info.md)
- [@ohos.distributedDeviceManager (Device Management)](reference/apis/js-apis-distributedDeviceManager.md)
- [@ohos.distributedHardware.deviceManager (Device Management)](reference/apis/js-apis-device-manager.md) - [@ohos.distributedHardware.deviceManager (Device Management)](reference/apis/js-apis-device-manager.md)
- [@ohos.driver.deviceManager (Peripheral Management)](reference/apis/js-apis-driver-deviceManager.md) - [@ohos.driver.deviceManager (Peripheral Management)](reference/apis/js-apis-driver-deviceManager.md)
- [@ohos.geoLocationManager (Geolocation Manager)](reference/apis/js-apis-geoLocationManager.md) - [@ohos.geoLocationManager (Geolocation Manager)](reference/apis/js-apis-geoLocationManager.md)
...@@ -1076,6 +1089,7 @@ ...@@ -1076,6 +1089,7 @@
- [@ohos.multimodalInput.touchEvent (Touch Event)](reference/apis/js-apis-touchevent.md) - [@ohos.multimodalInput.touchEvent (Touch Event)](reference/apis/js-apis-touchevent.md)
- [@ohos.multimodalInput.shortKey (Shortcut Key)](reference/apis/js-apis-shortKey.md) - [@ohos.multimodalInput.shortKey (Shortcut Key)](reference/apis/js-apis-shortKey.md)
- [@ohos.power (System Power Management)](reference/apis/js-apis-power.md) - [@ohos.power (System Power Management)](reference/apis/js-apis-power.md)
- [@ohos.resourceschedule.deviceStandby (Device Standby)](reference/apis/js-apis-resourceschedule-deviceStandby.md)
- [@ohos.runningLock (Runninglock)](reference/apis/js-apis-runninglock.md) - [@ohos.runningLock (Runninglock)](reference/apis/js-apis-runninglock.md)
- [@ohos.sensor (Sensor)](reference/apis/js-apis-sensor.md) - [@ohos.sensor (Sensor)](reference/apis/js-apis-sensor.md)
- [@ohos.settings (Data Item Settings)](reference/apis/js-apis-settings.md) - [@ohos.settings (Data Item Settings)](reference/apis/js-apis-settings.md)
...@@ -1100,6 +1114,7 @@ ...@@ -1100,6 +1114,7 @@
- [@ohos.enterprise.accountManager (Account Management)](reference/apis/js-apis-enterprise-accountManager.md) - [@ohos.enterprise.accountManager (Account Management)](reference/apis/js-apis-enterprise-accountManager.md)
- [@ohos.enterprise.adminManager (Enterprise Device Management)](reference/apis/js-apis-enterprise-adminManager.md) - [@ohos.enterprise.adminManager (Enterprise Device Management)](reference/apis/js-apis-enterprise-adminManager.md)
- [@ohos.enterprise.applicationManager (Application Management)](reference/apis/js-apis-enterprise-applicationManager.md) - [@ohos.enterprise.applicationManager (Application Management)](reference/apis/js-apis-enterprise-applicationManager.md)
- [@ohos.enterprise.browser (Browser Management)](reference/apis/js-apis-enterprise-browser.md)
- [@ohos.enterprise.bundleManager (Bundle Management)](reference/apis/js-apis-enterprise-bundleManager.md) - [@ohos.enterprise.bundleManager (Bundle Management)](reference/apis/js-apis-enterprise-bundleManager.md)
- [@ohos.enterprise.dateTimeManager (System Time Management)](reference/apis/js-apis-enterprise-dateTimeManager.md) - [@ohos.enterprise.dateTimeManager (System Time Management)](reference/apis/js-apis-enterprise-dateTimeManager.md)
- [@ohos.enterprise.deviceControl (Device Control Management)](reference/apis/js-apis-enterprise-deviceControl.md) - [@ohos.enterprise.deviceControl (Device Control Management)](reference/apis/js-apis-enterprise-deviceControl.md)
......
...@@ -4,29 +4,19 @@ ...@@ -4,29 +4,19 @@
### "usr/sbin/ninja: invalid option -- w" ### "usr/sbin/ninja: invalid option -- w"
- **Symptom** - **Symptom**<br>The build fails, and "usr/sbin/ninja: invalid option -- w" is displayed.
The build fails, and **usr/sbin/ninja: invalid option -- w** is displayed. - **Possible Causes**<br>The Ninja version in use does not support the **--w** option.
- **Possible Causes** - **Solution**<br>Uninstall Ninja and GN, and [install Ninja and GN of the required version](../../device-dev/get-code/gettools-ide.md).
The Ninja version in use does not support the **--w** option.
- **Solution**
Uninstall Ninja and GN, and [install Ninja and GN of the required version](../../device-dev/get-code/gettools-ide.md).
### "/usr/bin/ld: cannot find -lncurses" ### "/usr/bin/ld: cannot find -lncurses"
- **Symptom** - **Symptom**<br>The build fails, and "/usr/bin/ld: cannot find -lncurses" is displayed.
The build fails, and **/usr/bin/ld: cannot find -lncurses** is displayed. - **Possible Causes**<br>The ncurses library is not available.
- **Possible Causes** - **Solution**<br>
The ncurses library is not installed.
- **Solution**
```shell ```shell
sudo apt-get install lib32ncurses5-dev sudo apt-get install lib32ncurses5-dev
...@@ -34,15 +24,11 @@ ...@@ -34,15 +24,11 @@
### "line 77: mcopy: command not found" ### "line 77: mcopy: command not found"
- **Symptom** - **Symptom**<br>The build fails, and "line 77: mcopy: command not found" is displayed.
The build fails, and **line 77: mcopy: command not found** is displayed.
- **Possible Causes** - **Possible Causes**<br>mcopy is not available.
mcopy is not installed. - **Solution**<br>
- **Solution**
```shell ```shell
sudo apt-get install dosfstools mtools sudo apt-get install dosfstools mtools
...@@ -50,39 +36,25 @@ ...@@ -50,39 +36,25 @@
### "riscv32-unknown-elf-gcc: error trying to exec 'cc1': execvp: No such file or directory" ### "riscv32-unknown-elf-gcc: error trying to exec 'cc1': execvp: No such file or directory"
- **Symptom** - **Symptom**<br>The build fails, and "riscv32-unknown-elf-gcc: error trying to exec 'cc1': execvp: No such file or directory" is displayed.
The build fails, and the following information is displayed: <br>**riscv32-unknown-elf-gcc: error trying to exec 'cc1': execvp: No such file or directory**
- **Possible Causes**
You do not have the permission to access files in the RISC-V compiler directory. - **Possible Causes**<br>You do not have the permission to access files in the RISC-V compiler directory.
- **Solution** - **Solution**<br>1. Run the following command to locate **gcc_riscv32**.
1. Run the following command to locate **gcc_riscv32**: ```shell
which riscv32-unknown-elf-gcc
```shell ```
which riscv32-unknown-elf-gcc
```
2. Run the **chmod** command to change the permission for the directory to **755**.
2. Run the **chmod** command to change the directory permission to **755**.
### "No module named 'Crypto'" ### "No module named 'Crypto'"
- **Symptom** - **Symptom**<br>The build fails, and "No module named'Crypto'" is displayed.
The build fails, and **No module named 'Crypto'** is displayed.
- **Possible Causes** - **Possible Causes**<br>Crypto is not installed in Python3.
Crypto is not installed in Python3. - **Solution**<br>
- **Solution**
1. Run the following command to query the Python version: 1. Run the following command to query the Python version:
...@@ -96,17 +68,13 @@ ...@@ -96,17 +68,13 @@
sudo pip3 install pycryptodome sudo pip3 install pycryptodome
``` ```
### "xx.sh : xx unexpected operator" ### "xx.sh: xx unexpected operator"
- **Symptom**
The build fails, and **xx.sh [: xx unexpected operator** is displayed.
- **Possible Causes** - **Symptom**<br>The build fails, and " xx.sh [: xx unexpected operator" is displayed.
The build environment shell is not bash. - **Possible Causes**<br>The build environment shell is not bash.
- **Solution** - **Solution**<br>
```shell ```shell
sudo rm -rf /bin/sh sudo rm -rf /bin/sh
...@@ -114,20 +82,31 @@ ...@@ -114,20 +82,31 @@
``` ```
### "some services are not authenticated. Listed as follows" ### "some services are not authenticated. Listed as follow"
- **Symptom**<br>The build fails, and " some services are not authenticated. Listed as follow" is displayed.
- **Possible Causes**<br>In the .cfg file of the processes listed in the error message, **uid** is set to **root** or **system**. However, these processes are not high-privilege processes defined by the product.
- **Solution**<br>
Modify the process .cfg file to reduce the privilege level. Do not set **uid** to **root** or **system** unless necessary.
If a process must have the **root** or **system** privilege due to service requirements, modify the **high_privilege_process_list.json** file with the approval of the security experts. The **high_privilege_process_list.json** file is located in **vendor/***{company_name}/{product_name }***/security_config**.
- **Symptom** For example, the file for rk3586 is **//vendor/hihope/rk3568/security_config/high_privilege_process_list.json**.
The build fails, and "some services are not authenticated. Listed as follows" is displayed.
- **Possible Causes** ### "Error: some services do not match with critical whitelist"
For the processes listed in the error information, the UID is set to **root** or **system** in the process configuration files. However, these processes are not high-privilege processes defined by the product. - **Symptom**<br>The build fails, and "Error: some services do not match with critical whitelist" is displayed.
- **Solution** - **Possible Causes**<br>In the .cfg file of the processes listed in the error message, the **critical** field is defined and enabled. However, the **critical** field is not allowed for the processes, or the **critical** setting does not match the settings in the whitelist.
Modify the process configuration file to reduce the privilege level. Do not set **UID** to **root** or **system** unless necessary. - **Solution**<br>
If a process must have the **root** or **system** privilege due to service requirements, modify the **high_privilege_process_list.json** file with the approval of security experts. The **high_privilege_process_list.json** file is located in **vendor/**{*company_name*}/{*product_name*}**/security_config**. For example, the file for rk3586 is **//vendor/hihope/rk3568/security_config/high_privilege_process_list.json**. Remove the **critical** field or set the first bit of the **critical** field to **0** in the .cfg file of the processes. Do not enable the **critical** field unless necessary.
For details about how to use the **critical** field, see [Service Management](subsys-boot-init-service.md). If **critical** needs to be enabled for a process due to service requirements, modify the **//vendor/{company_name}/{product_name}/security_config/critical_reboot_process_list.json** file with the approval of the security experts.
For example, the critical_reboot process control whitelist of rk3586 is **//vendor/hihope/rk3568/security_config/critical_reboot_process_list.json**.
# App Access Control Subsystem ChangeLog # Application Access Control Subsystem Changelog
## cl.accessToken.1 Change of the Media and File Permission Group ## cl.accessToken.1 Change of the Media and Files Permission Group
The original Media and File permission group contains the following permissions: The original Media and File permission group contains the following permissions:
- ohos.permission.MEDIA_LOCATION - ohos.permission.MEDIA_LOCATION
- ohos.permission.READ_MEDIA - ohos.permission.READ_MEDIA
- ohos.permission.WRITE_MEDIA - ohos.permission.WRITE_MEDIA
Changed the permission group as follows: Changed the permission group as follows:
- Added **ohos.permission.MEDIA_LOCATION** to the Image and Video permission group. - Added **ohos.permission.MEDIA_LOCATION** to the Images and Video permission group.
- Added **ohos.permission.READ_MEDIA** and **ohos.permission.WRITE_MEDIA** to the File permission group. - Added **ohos.permission.READ_MEDIA** and **ohos.permission.WRITE_MEDIA** to the Documents permission group.
**Change Impact** **Change Impact**
The permission dialog boxes are displayed by permission group. The dialog box for requesting permissions is displayed by permission group.
- Before the change, if the three permissions are applied for an application, a dialog box for applying for the media and file permissions will be displayed only once. - Before the change, if the three permissions are applied for an application, a dialog box for requesting the media and file permissions will be displayed only once.
- After the change, if the three permissions are applied for an application, a dialog box for applying for the image and video permissions and a dialog box for applying for the file permission will be displayed. - After the change, if the three permissions are applied for an application, a dialog box for requesting the image and video permissions and a dialog box for requesting the document permission will be displayed.
**Key API/Component Changes** **Key API/Component Changes**
Permission group before the change: Permission groups before the change:
| Permission | Permission Group | | Permission | Permission Group |
| -------- | ---------------------------- | | -------- | ---------------------------- |
| ohos.permission.MEDIA_LOCATION | Media and File| | ohos.permission.MEDIA_LOCATION | Media and file|
| ohos.permission.READ_MEDIA | Media and File| | ohos.permission.READ_MEDIA | Media and file|
| ohos.permission.WRITE_MEDIA | Media and File| | ohos.permission.WRITE_MEDIA | Media and file|
Permission groups after the change: Permission groups after the change:
| Permission | Permission Group | | Permission | Permission Group |
| -------- | ---------------------------- | | -------- | ---------------------------- |
| ohos.permission.MEDIA_LOCATION | Image and Video| | ohos.permission.MEDIA_LOCATION | Images and videos |
| ohos.permission.READ_MEDIA | File| | ohos.permission.READ_MEDIA | Documents |
| ohos.permission.WRITE_MEDIA | File| | ohos.permission.WRITE_MEDIA | Documents |
**Adaptation Guide** **Adaptation Guide**
N/A N/A
## cl.accessToken.2 Change of the Permission Requesting Modes of the Telephony, Messaging, and Call Logs Permission Groups
The permissions of the Telephony, Messaging, and Call Logs permission groups are available only to system applications. The three permission groups contain the following permissions:
- ohos.permission.ANSWER_CALL
- ohos.permission.MANAGE_VOICEMAIL
- ohos.permission.READ_CELL_MESSAGES
- ohos.permission.READ_MESSAGES
- ohos.permission.RECEIVE_MMS
- ohos.permission.RECEIVE_SMS
- ohos.permission.RECEIVE_WAP_MESSAGES
- ohos.permission.SEND_MESSAGES
- ohos.permission.READ_CALL_LOG
- ohos.permission.WRITE_CALL_LOG
- ohos.permission.MEDIA_LOCATION
To enable third-party application developers to apply for these permissions, the method for requesting these permissions is changed to pre-authorization mode.
**Change Impact**
The system applications can obtain these permissions only in pre-authorization mode, rather than requesting these permissions through a pop-up window, .
**Key API/Component Changes**
N/A
**Adaptation Guide**
Apply for the preceding permissions in pre-authorization mode for system applications.
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
- [formBindingData](../reference/apis/js-apis-app-form-formBindingData.md):提供卡片数据绑定的能力,包括FormBindingData对象的创建、相关信息的描述。 - [formBindingData](../reference/apis/js-apis-app-form-formBindingData.md):提供卡片数据绑定的能力,包括FormBindingData对象的创建、相关信息的描述。
- [页面布局(Card.ets)](arkts-ui-widget-page-overview.md):提供声明式范式的UI接口能力。 - [页面布局(WidgetCard.ets)](arkts-ui-widget-page-overview.md):提供声明式范式的UI接口能力。
- [ArkTS卡片特有能力](arkts-ui-widget-event-overview.md):postCardAction用于卡片内部和提供方应用间的交互,仅在卡片中可以调用。 - [ArkTS卡片特有能力](arkts-ui-widget-event-overview.md):postCardAction用于卡片内部和提供方应用间的交互,仅在卡片中可以调用。
- [ArkTS卡片能力列表](arkts-ui-widget-page-overview.md#arkts卡片支持的页面能力):列举了能在ArkTS卡片中使用的API、组件、事件、属性和生命周期调度。 - [ArkTS卡片能力列表](arkts-ui-widget-page-overview.md#arkts卡片支持的页面能力):列举了能在ArkTS卡片中使用的API、组件、事件、属性和生命周期调度。
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
| action | string | 否 | 否 | 系统匹配时将忽略该参数,但仍可作为参数传递给目标应用组件。 | | action | string | 否 | 否 | 系统匹配时将忽略该参数,但仍可作为参数传递给目标应用组件。 |
| entities | Array&lt;string&gt; | 否 | 否 | 系统匹配时将忽略该参数,但仍可作为参数传递给目标应用组件。 | | entities | Array&lt;string&gt; | 否 | 否 | 系统匹配时将忽略该参数,但仍可作为参数传递给目标应用组件。 |
| flags | number | 否 | 否 | 不参与匹配,直接传递给系统处理,一般用来设置运行态信息,例如URI数据授权等。 | | flags | number | 否 | 否 | 不参与匹配,直接传递给系统处理,一般用来设置运行态信息,例如URI数据授权等。 |
| parameters | {[key:&nbsp;string]:&nbsp;any} | 否 | 否 | 不参与匹配,应用自定义数据将直接传递给目标应用组件。 | | parameters | {[key:&nbsp;string]:&nbsp;Object} | 否 | 否 | 不参与匹配,应用自定义数据将直接传递给目标应用组件。 |
## 隐式Want匹配原理 ## 隐式Want匹配原理
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
| action | string | 是 | 否 | | | action | string | 是 | 否 | |
| entities | Array&lt;string&gt; | 是 | 否 | | | entities | Array&lt;string&gt; | 是 | 否 | |
| flags | number | 否 | 否 | 不参与匹配,直接传递给系统处理,一般用来设置运行态信息,例如URI数据授权等。 | | flags | number | 否 | 否 | 不参与匹配,直接传递给系统处理,一般用来设置运行态信息,例如URI数据授权等。 |
| parameters | {[key:&nbsp;string]:&nbsp;any} | 否 | 否 | 不参与匹配,应用自定义数据将直接传递给目标应用组件。 | | parameters | {[key:&nbsp;string]:&nbsp;Object} | 否 | 否 | 不参与匹配,应用自定义数据将直接传递给目标应用组件。 |
从隐式Want的定义,可得知: 从隐式Want的定义,可得知:
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
| **接口名** | **描述** | | **接口名** | **描述** |
| -------- | -------- | | -------- | -------- |
| onContinue(wantParam&nbsp;:&nbsp;{[key:&nbsp;string]:&nbsp;any}):&nbsp;OnContinueResult | 迁移发起端在该回调中保存迁移所需要的数据,同时返回是否同意迁移:<br/>-&nbsp;AGREE:表示同意。<br/>-&nbsp;REJECT:表示拒绝:如应用在onContinue中异常可以直接REJECT。<br/>-&nbsp;MISMATCH:表示版本不匹配:迁移发起端应用可以在onContinue中获取到迁移接收端应用的版本号,进行协商后,如果版本不匹配导致无法迁移,可以返回该错误。 | | onContinue(wantParam&nbsp;:&nbsp;{[key:&nbsp;string]:&nbsp;Object}):&nbsp;OnContinueResult | 迁移发起端在该回调中保存迁移所需要的数据,同时返回是否同意迁移:<br/>-&nbsp;AGREE:表示同意。<br/>-&nbsp;REJECT:表示拒绝:如应用在onContinue中异常可以直接REJECT。<br/>-&nbsp;MISMATCH:表示版本不匹配:迁移发起端应用可以在onContinue中获取到迁移接收端应用的版本号,进行协商后,如果版本不匹配导致无法迁移,可以返回该错误。 |
| onCreate(want:&nbsp;Want,&nbsp;param:&nbsp;AbilityConstant.LaunchParam):&nbsp;void; | 应用迁移接收端为冷启动或多实例应用热启动时,在该回调中完成数据恢复,并触发页面恢复。详见[应用组件启动模式](uiability-launch-type.md) | | onCreate(want:&nbsp;Want,&nbsp;param:&nbsp;AbilityConstant.LaunchParam):&nbsp;void; | 应用迁移接收端为冷启动或多实例应用热启动时,在该回调中完成数据恢复,并触发页面恢复。详见[应用组件启动模式](uiability-launch-type.md) |
| onNewWant(want:&nbsp;Want,&nbsp;launchParams:&nbsp;AbilityConstant.LaunchParam):&nbsp;void; | 迁移接收端为单实例应用热启动时,在该回调中完成数据恢复,并触发页面恢复。详见[应用组件启动模式](uiability-launch-type.md) | | onNewWant(want:&nbsp;Want,&nbsp;launchParams:&nbsp;AbilityConstant.LaunchParam):&nbsp;void; | 迁移接收端为单实例应用热启动时,在该回调中完成数据恢复,并触发页面恢复。详见[应用组件启动模式](uiability-launch-type.md) |
......
...@@ -55,7 +55,7 @@ FormExtensionAbility类拥有如下API接口,具体的API介绍详见[接口 ...@@ -55,7 +55,7 @@ FormExtensionAbility类拥有如下API接口,具体的API介绍详见[接口
| onFormEvent(formId:&nbsp;string,&nbsp;message:&nbsp;string):&nbsp;void | 卡片提供方接收处理卡片事件的通知接口。 | | onFormEvent(formId:&nbsp;string,&nbsp;message:&nbsp;string):&nbsp;void | 卡片提供方接收处理卡片事件的通知接口。 |
| onRemoveForm(formId:&nbsp;string):&nbsp;void | 卡片提供方接收销毁卡片的通知接口。 | | onRemoveForm(formId:&nbsp;string):&nbsp;void | 卡片提供方接收销毁卡片的通知接口。 |
| onConfigurationUpdate(config:&nbsp;Configuration):&nbsp;void | 当系统配置更新时调用。 | | onConfigurationUpdate(config:&nbsp;Configuration):&nbsp;void | 当系统配置更新时调用。 |
| onShareForm?(formId:&nbsp;string):&nbsp;{&nbsp;[key:&nbsp;string]:&nbsp;any&nbsp;} | 卡片提供方接收卡片分享的通知接口。 | | onShareForm?(formId:&nbsp;string):&nbsp;{&nbsp;[key:&nbsp;string]:&nbsp;Object&nbsp;} | 卡片提供方接收卡片分享的通知接口。 |
formProvider类有如下API接口,具体的API介绍详见[接口文档](../reference/apis/js-apis-app-form-formProvider.md) formProvider类有如下API接口,具体的API介绍详见[接口文档](../reference/apis/js-apis-app-form-formProvider.md)
......
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
| onCreate?():&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want:&nbsp;Want,&nbsp;param:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate) | | onCreate?():&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want:&nbsp;Want,&nbsp;param:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate) |
| onWindowDisplayModeChanged?(isShownInMultiWindow:&nbsp;boolean,&nbsp;newConfig:&nbsp;resourceManager.Configuration):&nbsp;void; | Stage模型无对应接口 | 暂时未提供对应接口 | | onWindowDisplayModeChanged?(isShownInMultiWindow:&nbsp;boolean,&nbsp;newConfig:&nbsp;resourceManager.Configuration):&nbsp;void; | Stage模型无对应接口 | 暂时未提供对应接口 |
| onStartContinuation?():&nbsp;boolean; | Stage模型无对应接口 | Stage模型上,应用无需感知迁移是否成功(由应用发起迁移请求时感知),onStartContinuation废弃 | | onStartContinuation?():&nbsp;boolean; | Stage模型无对应接口 | Stage模型上,应用无需感知迁移是否成功(由应用发起迁移请求时感知),onStartContinuation废弃 |
| onSaveData?(data:&nbsp;Object):&nbsp;boolean; | \@ohos.app.ability.UIAbility.d.ts | [onContinue(wantParam&nbsp;:&nbsp;{[key:&nbsp;string]:&nbsp;any}):&nbsp;AbilityConstant.OnContinueResult;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncontinue) | | onSaveData?(data:&nbsp;Object):&nbsp;boolean; | \@ohos.app.ability.UIAbility.d.ts | [onContinue(wantParam&nbsp;:&nbsp;{[key:&nbsp;string]:&nbsp;Object}):&nbsp;AbilityConstant.OnContinueResult;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncontinue) |
| onCompleteContinuation?(result:&nbsp;number):&nbsp;void; | application\ContinueCallback.d.ts | [onContinueDone(result:&nbsp;number):&nbsp;void;](../reference/apis/js-apis-distributedMissionManager.md#continuecallback) | | onCompleteContinuation?(result:&nbsp;number):&nbsp;void; | application\ContinueCallback.d.ts | [onContinueDone(result:&nbsp;number):&nbsp;void;](../reference/apis/js-apis-distributedMissionManager.md#continuecallback) |
| onRestoreData?(data:&nbsp;Object):&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want:&nbsp;Want,&nbsp;param:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)<br/>[onNewWant(want:&nbsp;Want,&nbsp;launchParams:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant)<br/>多实例模式Ability迁移目标端在onCreate回调中完成数据恢复,单实例模式应用迁移目标端在onCreate回调中完成数据恢复,回调中通过判断launchParam.launchReason可获取迁移启动的场景,从而可以从Want中获取迁移前保存的数据 | | onRestoreData?(data:&nbsp;Object):&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want:&nbsp;Want,&nbsp;param:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)<br/>[onNewWant(want:&nbsp;Want,&nbsp;launchParams:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant)<br/>多实例模式Ability迁移目标端在onCreate回调中完成数据恢复,单实例模式应用迁移目标端在onCreate回调中完成数据恢复,回调中通过判断launchParam.launchReason可获取迁移启动的场景,从而可以从Want中获取迁移前保存的数据 |
| onRemoteTerminated?():&nbsp;void; | application\ContinueCallback.d.ts | [onContinueDone(result:&nbsp;number):&nbsp;void;](../reference/apis/js-apis-distributedMissionManager.md#continuecallback) | | onRemoteTerminated?():&nbsp;void; | application\ContinueCallback.d.ts | [onContinueDone(result:&nbsp;number):&nbsp;void;](../reference/apis/js-apis-distributedMissionManager.md#continuecallback) |
| onSaveAbilityState?(outState:&nbsp;PacMap):&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onSaveState(reason:&nbsp;AbilityConstant.StateType,&nbsp;wantParam&nbsp;:&nbsp;{[key:&nbsp;string]:&nbsp;any}):&nbsp;AbilityConstant.OnSaveResult;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonsavestate) | | onSaveAbilityState?(outState:&nbsp;PacMap):&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onSaveState(reason:&nbsp;AbilityConstant.StateType,&nbsp;wantParam&nbsp;:&nbsp;{[key:&nbsp;string]:&nbsp;Object}):&nbsp;AbilityConstant.OnSaveResult;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonsavestate) |
| onRestoreAbilityState?(inState:&nbsp;PacMap):&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want:&nbsp;Want,&nbsp;param:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)<br/>应用重启后会触发Ability的onCreate方法,通过判断launchParam.launchReason可获取自恢复的场景,从而可以从Want中获取重启前保存的数据 | | onRestoreAbilityState?(inState:&nbsp;PacMap):&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want:&nbsp;Want,&nbsp;param:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)<br/>应用重启后会触发Ability的onCreate方法,通过判断launchParam.launchReason可获取自恢复的场景,从而可以从Want中获取重启前保存的数据 |
| onInactive?():&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onBackground():&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonbackground) | | onInactive?():&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onBackground():&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonbackground) |
| onActive?():&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onForeground():&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonforeground) | | onActive?():&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onForeground():&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonforeground) |
......
...@@ -10,4 +10,4 @@ ...@@ -10,4 +10,4 @@
| onEvent?(formId:&nbsp;string,&nbsp;message:&nbsp;string):&nbsp;void; | \@ohos.app.form.FormExtensionAbility.d.ts | [onFormEvent(formId:&nbsp;string,&nbsp;message:&nbsp;string):&nbsp;void;](../reference/apis/js-apis-app-form-formExtensionAbility.md#onformevent) | | onEvent?(formId:&nbsp;string,&nbsp;message:&nbsp;string):&nbsp;void; | \@ohos.app.form.FormExtensionAbility.d.ts | [onFormEvent(formId:&nbsp;string,&nbsp;message:&nbsp;string):&nbsp;void;](../reference/apis/js-apis-app-form-formExtensionAbility.md#onformevent) |
| onDestroy?(formId:&nbsp;string):&nbsp;void; | \@ohos.app.form.FormExtensionAbility.d.ts | [onRemoveForm(formId:&nbsp;string):&nbsp;void;](../reference/apis/js-apis-app-form-formExtensionAbility.md#onremoveform) | | onDestroy?(formId:&nbsp;string):&nbsp;void; | \@ohos.app.form.FormExtensionAbility.d.ts | [onRemoveForm(formId:&nbsp;string):&nbsp;void;](../reference/apis/js-apis-app-form-formExtensionAbility.md#onremoveform) |
| onAcquireFormState?(want:&nbsp;Want):&nbsp;formInfo.FormState; | \@ohos.app.form.FormExtensionAbility.d.ts | [onAcquireFormState?(want:&nbsp;Want):&nbsp;formInfo.FormState;](../reference/apis/js-apis-app-form-formExtensionAbility.md#onacquireformstate) | | onAcquireFormState?(want:&nbsp;Want):&nbsp;formInfo.FormState; | \@ohos.app.form.FormExtensionAbility.d.ts | [onAcquireFormState?(want:&nbsp;Want):&nbsp;formInfo.FormState;](../reference/apis/js-apis-app-form-formExtensionAbility.md#onacquireformstate) |
| onShare?(formId:&nbsp;string):&nbsp;{[key:&nbsp;string]:&nbsp;any}; | \@ohos.app.form.FormExtensionAbility.d.ts | [onShareForm?(formId:&nbsp;string):&nbsp;{&nbsp;[key:&nbsp;string]:&nbsp;any&nbsp;};](../reference/apis/js-apis-app-form-formExtensionAbility.md#onshareform) | | onShare?(formId:&nbsp;string):&nbsp;{[key:&nbsp;string]:&nbsp;Object}; | \@ohos.app.form.FormExtensionAbility.d.ts | [onShareForm?(formId:&nbsp;string):&nbsp;{&nbsp;[key:&nbsp;string]:&nbsp;Object&nbsp;};](../reference/apis/js-apis-app-form-formExtensionAbility.md#onshareform) |
...@@ -354,16 +354,10 @@ struct MultiLaneList { ...@@ -354,16 +354,10 @@ struct MultiLaneList {
struct SideBarSample { struct SideBarSample {
@StorageLink('currentBreakpoint') private currentBreakpoint: string = "md"; @StorageLink('currentBreakpoint') private currentBreakpoint: string = "md";
private breakpointSystem: BreakpointSystem = new BreakpointSystem() private breakpointSystem: BreakpointSystem = new BreakpointSystem()
@State showSideBar: boolean = false
@State selectIndex: number = 0; @State selectIndex: number = 0;
aboutToAppear() { aboutToAppear() {
this.breakpointSystem.register() this.breakpointSystem.register()
if (this.currentBreakpoint === 'sm') {
this.showSideBar = false
} else {
this.showSideBar = true
}
} }
aboutToDisappear() { aboutToDisappear() {
...@@ -382,9 +376,6 @@ struct SideBarSample { ...@@ -382,9 +376,6 @@ struct SideBarSample {
.height(36) .height(36)
.onClick(() => { .onClick(() => {
this.selectIndex = index this.selectIndex = index
if (this.currentBreakpoint === 'sm') {
this.showSideBar = false
}
}) })
} }
...@@ -412,9 +403,8 @@ struct SideBarSample { ...@@ -412,9 +403,8 @@ struct SideBarSample {
.maxSideBarWidth(this.currentBreakpoint === 'sm' ? '100%' : '33.33%') .maxSideBarWidth(this.currentBreakpoint === 'sm' ? '100%' : '33.33%')
.showControlButton(this.currentBreakpoint === 'sm') .showControlButton(this.currentBreakpoint === 'sm')
.autoHide(false) .autoHide(false)
.showSideBar(this.showSideBar)
.onChange((isBarShow: boolean) => { .onChange((isBarShow: boolean) => {
this.showSideBar = isBarShow
}) })
} }
} }
......
...@@ -420,7 +420,7 @@ extensionAbilities示例: ...@@ -420,7 +420,7 @@ extensionAbilities示例:
## requestPermissions标签 ## requestPermissions标签
该标签标识应用运行时需向系统申请的权限集合。 该标签标识应用运行时需向系统申请的权限集合,权限设置方式参见[指导](../security/accesstoken-guidelines.md)
> **说明:** > **说明:**
> >
......
...@@ -202,7 +202,7 @@ onContinue(wantParam: { [key: string]: Object }): AbilityConstant.OnContinueResu ...@@ -202,7 +202,7 @@ onContinue(wantParam: { [key: string]: Object }): AbilityConstant.OnContinueResu
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| wantParam | {[key:&nbsp;string]:&nbsp;any} | 是 | want相关参数。 | | wantParam | {[key:&nbsp;string]:&nbsp;Object} | 是 | want相关参数。 |
**返回值:** **返回值:**
...@@ -289,7 +289,7 @@ onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: Objec ...@@ -289,7 +289,7 @@ onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: Objec
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| reason | [AbilityConstant.StateType](js-apis-app-ability-abilityConstant.md#abilityconstantstatetype) | 是 | 回调保存状态的原因。 | | reason | [AbilityConstant.StateType](js-apis-app-ability-abilityConstant.md#abilityconstantstatetype) | 是 | 回调保存状态的原因。 |
| wantParam | {[key:&nbsp;string]:&nbsp;any} | 是 | want相关参数。 | | wantParam | {[key:&nbsp;string]:&nbsp;Object} | 是 | want相关参数。 |
**返回值:** **返回值:**
......
# @ohos.app.ability.UIExtensionAbility (带界面扩展能力基类)
UIExtensionAbility是特定场景下带界面扩展能力的基类,继承自[ExtensionAbility](js-apis-app-ability-extensionAbility.md),新增带界面扩展能力相关的属性和方法。不支持开发者直接继承该基类。
> **说明:**
>
> 本模块首批接口从API version 10 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在Stage模型下使用。
## 导入模块
```ts
import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility';
```
## 属性
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| context | [UIExtensionContext](js-apis-inner-application-uiExtensionContext.md) | 是 | 否 | 上下文。 |
## UIExtensionAbility.onCreate
onCreate(): void
UIExtensionAbility创建时回调,执行初始化业务逻辑操作。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
## UIExtensionAbility.onSessionCreate
onSessionCreate(want: Want, session: UIExtensionContentSession): void
当UIExtensionAbility界面内容对象创建后调用。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-app-ability-want.md) | 是 | 当前UIExtensionAbility的Want类型信息,包括ability名称、bundle名称等。 |
| session | [UIExtensionContentSession](js-apis-app-ability-uiExtensionContentSession.md) | 是 | UIExtensionAbility界面内容相关信息。 |
## UIExtensionAbility.onSessionDestroy
onSessionDestroy(session: UIExtensionContentSession): void
当UIExtensionAbility界面内容对象销毁后调用。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| session | [UIExtensionContentSession](js-apis-app-ability-uiExtensionContentSession.md) | 是 | UIExtensionAbility界面内容相关信息。 |
## UIExtensionAbility.onForeground
onForeground(): void;
UIExtensionAbility生命周期回调,当UIExtensionAbility从后台转到前台时触发。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
## UIExtensionAbility.onBackground
onBackground(): void;
UIExtensionAbility生命周期回调,当UIExtensionAbility从前台转到后台时触发。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
## UIExtensionAbility.onDestroy
onDestroy(): void | Promise&lt;void&gt;;
UIExtensionAbility生命周期回调,在销毁时回调,执行资源清理等操作。
在执行完onDestroy生命周期回调后,应用可能会退出,从而可能导致onDestroy中的异步函数未能正确执行,比如异步写入数据库。可以使用异步生命周期,以确保异步onDestroy完成后再继续后续的生命周期。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
# @ohos.app.ability.UIExtensionContentSession (带界面扩展能力界面操作类)
UIExtensionContentSession是[UIExtensionAbility](js-apis-app-ability-uiExtensionAbility.md)加载界面内容时创建的实例对象,当UIExtensionComponent控件拉起指定的UIExtensionAbility时,UIExtensionAbility会创建UIExtensionContentSession对象,并通过[onSessionCreate](js-apis-app-ability-uiExtensionAbility.md#uiextensionabilityonsessioncreate)回调传递给开发者。一个UIExtensionComponent控件对应一个UIExtensionContentSession对象,提供界面加载,结果通知等方法。每个UIExtensionAbility的UIExtensionContentSession之间互不影响,可以各自进行操作。
> **说明:**
>
> 本模块首批接口从API version 10 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在Stage模型下使用。
## 导入模块
```ts
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
```
## UIExtensionContentSession.sendData
sendData(data: { [key: string]: Object }): void
发送数据给UIExtensionComponent控件。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| data | {[key:&nbsp;string]:&nbsp;Object} | 是 | 发送给UIExtensionComponent控件的数据参数。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 16000050 | Internal error. |
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
## UIExtensionContentSession.setReceiveDataCallback
setReceiveDataCallback(callback: (data: { [key: string]: Object }) => void): void
设置从UIExtensionComponent控件接收数据的回调方法。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | (data: { [key: string]: Object }) => void | 是 | 接收数据的回调方法。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 16000050 | Internal error. |
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
## UIExtensionContentSession.loadContent
loadContent(path: string, storage?: LocalStorage): Promise&lt;void&gt;
为当前UIExtensionComponent控件对应的窗口加载与LocalStorage相关联的具体页面内容。
**系统能力:** SystemCapability.Ability.AbilityRuntime.AbilityCore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | 是 | 设置加载页面的路径。 |
| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 否 | 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 16000050 | Internal error. |
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
## UIExtensionContentSession.terminateSelf
terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
停止UIExtensionContentSession对应的窗口界面对象(callback形式)。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 停止UIExtensionContentSession对应的窗口界面对象的回调函数。 |
## UIExtensionContentSession.terminateSelf
terminateSelf(): Promise&lt;void&gt;;
停止UIExtensionContentSession对应的窗口界面对象(promise形式)。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 停止UIExtensionContentSession对应的窗口界面对象的回调函数。 |
## UIExtensionContentSession.terminateSelfWithResult
terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;void&gt;): void;
停止UIExtensionContentSession对应的窗口界面对象,并将结果返回给UIExtensionComponent控件(callback形式)。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | 是 | 返回给UIExtensionComponent控件的信息。 |
| callback | AsyncCallback&lt;void&gt; | 是 | callback形式返回停止结果。 |
## UIExtensionContentSession.terminateSelfWithResult
terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;
停止UIExtensionContentSession对应的窗口界面对象,并将结果返回给UIExtensionComponent控件(promise形式)。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | 是 | 返回给UIExtensionComponent控件的信息。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | promise形式返回停止结果。 |
## UIExtensionContentSession.setWindowBackgroundColor
setWindowBackgroundColor(color: string): void
设置UIExtensionAbility加载界面的背景色。该接口需要在[loadContent()](#uiextensioncontentsessionloadcontent)调用生效后使用。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00``#FF00FF00`。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 16000050 | Internal error. |
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
## UIExtensionContentSession.setWindowPrivacyMode
setWindowPrivacyMode(isPrivacyMode: boolean): Promise&lt;void&gt;
设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。
**系统能力:** SystemCapability.Ability.AbilityRuntime.AbilityCore
**需要权限:** ohos.permission.PRIVACY_WINDOW
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------- | ------- | -- | ----------------------------------------------------- |
| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------ |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
## UIExtensionContentSession.setWindowPrivacyMode
setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback&lt;void&gt;): void
设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。
**系统能力:** SystemCapability.Ability.AbilityRuntime.AbilityCore
**需要权限:** ohos.permission.PRIVACY_WINDOW
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------- | ------------------------- | -- | ------------------------------------------------------ |
| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
...@@ -327,11 +327,27 @@ createController(sessionId: string): Promise\<AVSessionController> ...@@ -327,11 +327,27 @@ createController(sessionId: string): Promise\<AVSessionController>
**示例:** **示例:**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let sessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
sessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
}
});
let currentAVcontroller; let currentAVcontroller;
avSession.createController(currentAVSession.sessionId).then((avcontroller) => { avSession.createController(sessionId).then((avcontroller) => {
currentAVcontroller = avcontroller; currentAVcontroller = avcontroller;
console.info(`CreateController : SUCCESS : ${currentAVcontroller.sessionId}`); console.info('CreateController : SUCCESS ');
}).catch((err) => { }).catch((err) => {
console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
...@@ -367,13 +383,30 @@ createController(sessionId: string, callback: AsyncCallback\<AVSessionController ...@@ -367,13 +383,30 @@ createController(sessionId: string, callback: AsyncCallback\<AVSessionController
**示例:** **示例:**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let sessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
sessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
}
});
let currentAVcontroller; let currentAVcontroller;
avSession.createController(currentAVSession.sessionId, function (err, avcontroller) { avSession.createController(sessionId, function (err, avcontroller) {
if (err) { if (err) {
console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
currentAVcontroller = avcontroller; currentAVcontroller = avcontroller;
console.info(`CreateController : SUCCESS : ${currentAVcontroller.sessionId}`); console.info('CreateController : SUCCESS ');
} }
}); });
``` ```
...@@ -1293,6 +1326,23 @@ getAVCastController(sessionId: string, callback: AsyncCallback\<AVCastController ...@@ -1293,6 +1326,23 @@ getAVCastController(sessionId: string, callback: AsyncCallback\<AVCastController
**示例:** **示例:**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let sessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
sessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
}
});
let aVCastController; let aVCastController;
avSession.getAVCastController(sessionId ,function (err, avcontroller) { avSession.getAVCastController(sessionId ,function (err, avcontroller) {
if (err) { if (err) {
...@@ -1339,6 +1389,23 @@ getAVCastController(sessionId: string): Promise\<AVCastController>; ...@@ -1339,6 +1389,23 @@ getAVCastController(sessionId: string): Promise\<AVCastController>;
**示例:** **示例:**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let sessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
sessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
}
});
let aVCastController; let aVCastController;
avSession.getAVCastController(sessionId).then((avcontroller) => { avSession.getAVCastController(sessionId).then((avcontroller) => {
aVCastController = avcontroller; aVCastController = avcontroller;
...@@ -1379,8 +1446,25 @@ startCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCal ...@@ -1379,8 +1446,25 @@ startCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCal
**示例:** **示例:**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let currSessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
currSessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`);
}
});
let myToken = { let myToken = {
sessionId: sessionId, sessionId: currSessionId,
} }
let castDevice; let castDevice;
avSession.on('deviceAvailable', (device) => { avSession.on('deviceAvailable', (device) => {
...@@ -1432,8 +1516,25 @@ startCasting(session: SessionToken, device: OutputDeviceInfo): Promise\<void> ...@@ -1432,8 +1516,25 @@ startCasting(session: SessionToken, device: OutputDeviceInfo): Promise\<void>
**示例:** **示例:**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let currSessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
currSessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`);
}
});
let myToken = { let myToken = {
sessionId: sessionId, sessionId: currSessionId,
} }
let castDevice; let castDevice;
avSession.on('deviceAvailable', (device) => { avSession.on('deviceAvailable', (device) => {
...@@ -1474,15 +1575,27 @@ stopCasting(session: SessionToken, callback: AsyncCallback\<void>): void ...@@ -1474,15 +1575,27 @@ stopCasting(session: SessionToken, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let currSessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
currSessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`);
}
});
let myToken = { let myToken = {
sessionId: sessionId, sessionId: currSessionId,
} }
let castDevice; avSession.stopCasting(myToken, function (err) {
avSession.on('deviceAvailable', (device) => {
castDevice = device;
console.info(`on deviceAvailable : ${device} `);
});
avSession.stopCasting(myToken, castDevice, function (err) {
if (err) { if (err) {
console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -1523,14 +1636,26 @@ stopCasting(session: SessionToken): Promise\<void> ...@@ -1523,14 +1636,26 @@ stopCasting(session: SessionToken): Promise\<void>
**示例:** **示例:**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let currSessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
currSessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`);
}
});
let myToken = { let myToken = {
sessionId: sessionId, sessionId: currSessionId,
} }
let castDevice;
avSession.on('deviceAvailable', (device) => {
castDevice = device;
console.info(`on deviceAvailable : ${device} `);
});
avSession.stopCasting(myToken).then(() => { avSession.stopCasting(myToken).then(() => {
console.info(`stopCasting successfully`); console.info(`stopCasting successfully`);
}).catch((err) => { }).catch((err) => {
...@@ -5885,7 +6010,7 @@ avsessionController.getExtras(function (err, extras) { ...@@ -5885,7 +6010,7 @@ avsessionController.getExtras(function (err, extras) {
if (err) { if (err) {
console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
console.info(`getExtras : SUCCESS : assetId : ${metadata.assetId}`); console.info(`getExtras : SUCCESS : assetId : ${extras}`);
} }
}); });
``` ```
......
# AbilityResult # AbilityResult
定义Ability被拉起并退出后返回的结果码和数据,可以通过[startAbilityForResult](js-apis-ability-featureAbility.md#featureabilitystartabilityforresult7)获取被拉起Ability退出后返回的AbilityResult对象,被startAbilityForResult拉起的Ability对象可以通过[terminateSelfWithResult](js-apis-ability-featureAbility.md#featureabilityterminateselfwithresult7)返回AbilityResult对象。 定义Ability被拉起并退出后返回的结果码和数据。
Stage模型下,可以通过[startAbilityForResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartabilityforresult)获取被拉起Ability退出后返回的AbilityResult对象,被startAbilityForResult拉起的Ability对象可以通过[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)返回AbilityResult对象。
FA模型下,可以通过[startAbilityForResult](js-apis-ability-featureAbility.md#featureabilitystartabilityforresult7)获取被拉起Ability退出后返回的AbilityResult对象,被startAbilityForResult拉起的Ability对象可以通过[terminateSelfWithResult](js-apis-ability-featureAbility.md#featureabilityterminateselfwithresult7)返回AbilityResult对象。
> **说明:** > **说明:**
> >
...@@ -8,6 +10,12 @@ ...@@ -8,6 +10,12 @@
## 导入模块 ## 导入模块
Stage模型下:
```ts
import common from '@ohos.app.ability.common';
```
FA模型下:
```ts ```ts
import ability from '@ohos.ability.ability'; import ability from '@ohos.ability.ability';
``` ```
......
# UIExtensionContext
UIExtensionContext是[UIExtensionAbility](js-apis-app-ability-uiExtensionAbility.md)的上下文环境,继承自[ExtensionContext](js-apis-inner-application-extensionContext.md),提供UIExtensionAbility的相关配置信息以及操作UIAbility的方法,如启动UIAbility等。
> **说明:**
>
> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块接口仅可在Stage模型下使用。
## 导入模块
```ts
import common from '@ohos.app.ability.common';
```
## UIExtensionContext.startAbility
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
启动Ability(callback形式)。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限
- 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限
- 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 |
| callback | AsyncCallback&lt;void&gt; | 是 | callback形式返回启动结果。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 16000001 | The specified ability does not exist. |
| 16000002 | Incorrect ability type. |
| 16000004 | Can not start invisible component. |
| 16000005 | The specified process does not have the permission. |
| 16000006 | Cross-user operations are not allowed. |
| 16000008 | The crowdtesting application expires. |
| 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000010 | The call with the continuation flag is forbidden. |
| 16000011 | The context does not exist. |
| 16000012 | The application is controlled. |
| 16000013 | The application is controlled by EDM. |
| 16000050 | Internal error. |
| 16000053 | The ability is not on the top of the UI. |
| 16000055 | Installation-free timed out. |
| 16200001 | The caller has been released. |
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
## UIExtensionContext.startAbility
startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void;
启动Ability(callback形式)。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限
- 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限
- 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 |
| options | [StartOptions](js-apis-app-ability-startOptions.md) | 是 | 启动Ability所携带的参数。 |
| callback | AsyncCallback&lt;void&gt; | 是 | callback形式返回启动结果。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 16000001 | The specified ability does not exist. |
| 16000002 | Incorrect ability type. |
| 16000004 | Can not start invisible component. |
| 16000005 | The specified process does not have the permission. |
| 16000006 | Cross-user operations are not allowed. |
| 16000008 | The crowdtesting application expires. |
| 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000010 | The call with the continuation flag is forbidden. |
| 16000011 | The context does not exist. |
| 16000012 | The application is controlled. |
| 16000013 | The application is controlled by EDM. |
| 16000050 | Internal error. |
| 16000053 | The ability is not on the top of the UI. |
| 16000055 | Installation-free timed out. |
| 16200001 | The caller has been released. |
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
## UIExtensionContext.startAbility
startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;;
启动Ability(promise形式)。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限
- 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限
- 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 |
| options | [StartOptions](js-apis-app-ability-startOptions.md) | 否 | 启动Ability所携带的参数。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | Promise形式返回启动结果。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 16000001 | The specified ability does not exist. |
| 16000002 | Incorrect ability type. |
| 16000004 | Can not start invisible component. |
| 16000005 | The specified process does not have the permission. |
| 16000006 | Cross-user operations are not allowed. |
| 16000008 | The crowdtesting application expires. |
| 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000010 | The call with the continuation flag is forbidden. |
| 16000011 | The context does not exist. |
| 16000012 | The application is controlled. |
| 16000013 | The application is controlled by EDM. |
| 16000050 | Internal error. |
| 16000053 | The ability is not on the top of the UI. |
| 16000055 | Installation-free timed out. |
| 16200001 | The caller has been released. |
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
## UIExtensionContext.startAbilityForResult
startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): void;
启动一个Ability。Ability被启动后,有如下情况(callback形式):
- 正常情况下可通过调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止并且返回结果给调用方。
- 异常情况下比如杀死Ability会返回异常信息给调用方, 异常信息中resultCode为-1。
- 如果被启动的Ability模式是单实例模式, 不同应用多次调用该接口启动这个Ability,当这个Ability调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止时,只将正常结果返回给最后一个调用方, 其它调用方返回异常信息, 异常信息中resultCode为-1。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限
- 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限
- 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 |
| callback | AsyncCallback&lt;[AbilityResult](js-apis-inner-ability-abilityResult.md)&gt; | 是 | 执行结果回调函数。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 16000001 | The specified ability does not exist. |
| 16000002 | Incorrect ability type. |
| 16000004 | Can not start invisible component. |
| 16000005 | The specified process does not have the permission. |
| 16000006 | Cross-user operations are not allowed. |
| 16000008 | The crowdtesting application expires. |
| 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000010 | The call with the continuation flag is forbidden. |
| 16000011 | The context does not exist. |
| 16000012 | The application is controlled. |
| 16000013 | The application is controlled by EDM. |
| 16000050 | Internal error. |
| 16000053 | The ability is not on the top of the UI. |
| 16000055 | Installation-free timed out. |
| 16200001 | The caller has been released. |
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
## UIExtensionContext.startAbilityForResult
startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback&lt;AbilityResult&gt;): void;
启动一个Ability。Ability被启动后,有如下情况(callback形式):
- 正常情况下可通过调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止并且返回结果给调用方。
- 异常情况下比如杀死Ability会返回异常信息给调用方,异常信息中resultCode为-1。
- 如果被启动的Ability模式是单实例模式, 不同应用多次调用该接口启动这个Ability,当这个Ability调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止时,只将正常结果返回给最后一个调用方,其它调用方返回异常信息, 异常信息中resultCode为-1。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限
- 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限
- 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 |
| options | [StartOptions](js-apis-app-ability-startOptions.md) | 是 | 启动Ability所携带的参数。 |
| callback | AsyncCallback&lt;[AbilityResult](js-apis-inner-ability-abilityResult.md)&gt; | 是 | 执行结果回调函数。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 16000001 | The specified ability does not exist. |
| 16000002 | Incorrect ability type. |
| 16000004 | Can not start invisible component. |
| 16000005 | The specified process does not have the permission. |
| 16000006 | Cross-user operations are not allowed. |
| 16000008 | The crowdtesting application expires. |
| 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000010 | The call with the continuation flag is forbidden. |
| 16000011 | The context does not exist. |
| 16000012 | The application is controlled. |
| 16000013 | The application is controlled by EDM. |
| 16000050 | Internal error. |
| 16000053 | The ability is not on the top of the UI. |
| 16000055 | Installation-free timed out. |
| 16200001 | The caller has been released. |
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
## UIExtensionContext.startAbilityForResult
startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityResult&gt;;
启动一个Ability。Ability被启动后,有如下情况(promise形式):
- 正常情况下可通过调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止并且返回结果给调用方。
- 异常情况下比如杀死Ability会返回异常信息给调用方, 异常信息中resultCode为-1。
- 如果被启动的Ability模式是单实例模式, 不同应用多次调用该接口启动这个Ability,当这个Ability调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止时,只将正常结果返回给最后一个调用方, 其它调用方返回异常信息, 异常信息中resultCode为-1。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限
- 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限
- 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 |
| options | [StartOptions](js-apis-app-ability-startOptions.md) | 否 | 启动Ability所携带的参数。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;[AbilityResult](js-apis-inner-ability-abilityResult.md)&gt; | Promise形式返回执行结果。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 16000001 | The specified ability does not exist. |
| 16000002 | Incorrect ability type. |
| 16000004 | Can not start invisible component. |
| 16000005 | The specified process does not have the permission. |
| 16000006 | Cross-user operations are not allowed. |
| 16000008 | The crowdtesting application expires. |
| 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000010 | The call with the continuation flag is forbidden. |
| 16000011 | The context does not exist. |
| 16000012 | The application is controlled. |
| 16000013 | The application is controlled by EDM. |
| 16000050 | Internal error. |
| 16000053 | The ability is not on the top of the UI. |
| 16000055 | Installation-free timed out. |
| 16200001 | The caller has been released. |
错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
...@@ -310,7 +310,7 @@ getTaskPoolInfo(): TaskPoolInfo ...@@ -310,7 +310,7 @@ getTaskPoolInfo(): TaskPoolInfo
**示例:** **示例:**
```ts ```ts
let taskpoolInfo:TaskPoolInfo = taskpool.getTaskPoolInfo(); let taskpoolInfo = taskpool.getTaskPoolInfo();
``` ```
## Priority ## Priority
...@@ -363,7 +363,7 @@ for (let i = 0; i < allCount; i++) { ...@@ -363,7 +363,7 @@ for (let i = 0; i < allCount; i++) {
## Task ## Task
表示任务。使用以下方法前,需要先构造Task。 表示任务。使用[constructor](#constructor)方法构造Task。
### constructor ### constructor
...@@ -404,7 +404,7 @@ let task = new taskpool.Task(printArgs, "this is my first Task"); ...@@ -404,7 +404,7 @@ let task = new taskpool.Task(printArgs, "this is my first Task");
static isCanceled(): boolean static isCanceled(): boolean
检查当前正在运行的任务是否已取消。 检查当前正在运行的任务是否已取消。使用该方法前需要先构造Task。
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
...@@ -469,7 +469,7 @@ taskpool.execute(task).then((res)=>{ ...@@ -469,7 +469,7 @@ taskpool.execute(task).then((res)=>{
setTransferList(transfer?: ArrayBuffer[]): void setTransferList(transfer?: ArrayBuffer[]): void
设置任务的传输列表。 设置任务的传输列表。使用该方法前需要先构造Task。
> **说明:**<br/> > **说明:**<br/>
> 此接口可以设置任务池中ArrayBuffer的transfer列表,transfer列表中的ArrayBuffer对象在传输时不会复制buffer内容到工作线程而是转移buffer控制权至工作线程,传输后当前的ArrayBuffer失效。 > 此接口可以设置任务池中ArrayBuffer的transfer列表,transfer列表中的ArrayBuffer对象在传输时不会复制buffer内容到工作线程而是转移buffer控制权至工作线程,传输后当前的ArrayBuffer失效。
...@@ -519,7 +519,8 @@ console.info("testTransfer view1 byteLength: " + view1.byteLength); ...@@ -519,7 +519,8 @@ console.info("testTransfer view1 byteLength: " + view1.byteLength);
| arguments | unknown[] | 是 | 是 | 创建任务传入函数所需的参数,支持的参数类型请查[序列化支持类型](#序列化支持类型)。 | | arguments | unknown[] | 是 | 是 | 创建任务传入函数所需的参数,支持的参数类型请查[序列化支持类型](#序列化支持类型)。 |
## TaskGroup<sup>10+</sup> ## TaskGroup<sup>10+</sup>
表示任务组。使用以下方法前,需要先构造TaskGroup。
表示任务组。使用[constructor](#constructor10)方法构造TaskGroup。
### constructor<sup>10+</sup> ### constructor<sup>10+</sup>
...@@ -539,7 +540,7 @@ let taskGroup = new taskpool.TaskGroup(); ...@@ -539,7 +540,7 @@ let taskGroup = new taskpool.TaskGroup();
addTask(func: Function, ...args: unknown[]): void addTask(func: Function, ...args: unknown[]): void
将待执行的函数添加到任务组中。 将待执行的函数添加到任务组中。使用该方法前需要先构造TaskGroup。
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
...@@ -575,7 +576,7 @@ taskGroup.addTask(printArgs, 100); // 100: test number ...@@ -575,7 +576,7 @@ taskGroup.addTask(printArgs, 100); // 100: test number
addTask(task: Task): void addTask(task: Task): void
将创建好的任务添加到任务组中。 将创建好的任务添加到任务组中。使用该方法前需要先构造TaskGroup。
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
......
...@@ -63,7 +63,7 @@ import wallpaper from '@ohos.wallpaper'; ...@@ -63,7 +63,7 @@ import wallpaper from '@ohos.wallpaper';
setVideo(source: string, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void setVideo(source: string, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
将视频资源设置为桌面或锁屏的动态壁纸。 将视频资源设置为桌面或锁屏的动态壁纸。使用callback异步回调。
**需要权限**:ohos.permission.SET_WALLPAPER **需要权限**:ohos.permission.SET_WALLPAPER
...@@ -101,7 +101,7 @@ try { ...@@ -101,7 +101,7 @@ try {
setVideo(source: string, wallpaperType: WallpaperType): Promise&lt;void&gt; setVideo(source: string, wallpaperType: WallpaperType): Promise&lt;void&gt;
将视频资源设置为桌面或锁屏的动态壁纸。 将视频资源设置为桌面或锁屏的动态壁纸。使用promise异步回调。
**需要权限**:ohos.permission.SET_WALLPAPER **需要权限**:ohos.permission.SET_WALLPAPER
...@@ -370,7 +370,7 @@ let minWidth = wallpaper.getMinWidthSync(); ...@@ -370,7 +370,7 @@ let minWidth = wallpaper.getMinWidthSync();
restore(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void restore(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
移除指定类型的壁纸,恢复为默认显示的壁纸。 移除指定类型的壁纸,恢复为默认显示的壁纸。使用callback异步回调。
**需要权限**:ohos.permission.SET_WALLPAPER **需要权限**:ohos.permission.SET_WALLPAPER
...@@ -401,7 +401,7 @@ wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { ...@@ -401,7 +401,7 @@ wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => {
restore(wallpaperType: WallpaperType): Promise&lt;void&gt; restore(wallpaperType: WallpaperType): Promise&lt;void&gt;
移除指定类型的壁纸,恢复为默认显示的壁纸。 移除指定类型的壁纸,恢复为默认显示的壁纸。使用promise异步回调。
**需要权限**:ohos.permission.SET_WALLPAPER **需要权限**:ohos.permission.SET_WALLPAPER
...@@ -435,7 +435,7 @@ wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { ...@@ -435,7 +435,7 @@ wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
将指定资源设置为指定类型的壁纸。 将指定资源设置为指定类型的壁纸。使用callback异步回调。
**需要权限**:ohos.permission.SET_WALLPAPER **需要权限**:ohos.permission.SET_WALLPAPER
...@@ -490,7 +490,7 @@ imageSource.createPixelMap(opts).then((pixelMap) => { ...@@ -490,7 +490,7 @@ imageSource.createPixelMap(opts).then((pixelMap) => {
setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt; setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;
将指定资源设置为指定类型的壁纸。 将指定资源设置为指定类型的壁纸。使用promise异步回调。
**需要权限**:ohos.permission.SET_WALLPAPER **需要权限**:ohos.permission.SET_WALLPAPER
...@@ -546,7 +546,7 @@ imageSource.createPixelMap(opts).then((pixelMap) => { ...@@ -546,7 +546,7 @@ imageSource.createPixelMap(opts).then((pixelMap) => {
getImage(wallpaperType: WallpaperType, callback: AsyncCallback&lt;image.PixelMap&gt;): void; getImage(wallpaperType: WallpaperType, callback: AsyncCallback&lt;image.PixelMap&gt;): void;
获取壁纸图片的像素图。 获取壁纸图片的像素图。使用callback异步回调。
**需要权限**:ohos.permission.GET_WALLPAPER **需要权限**:ohos.permission.GET_WALLPAPER
...@@ -578,7 +578,7 @@ wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM, function (error, da ...@@ -578,7 +578,7 @@ wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM, function (error, da
getImage(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt; getImage(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt;
获取壁纸图片的像素图。 获取壁纸图片的像素图。使用promise异步回调。
**需要权限**:ohos.permission.GET_WALLPAPER **需要权限**:ohos.permission.GET_WALLPAPER
......
...@@ -22,11 +22,17 @@ LoadingProgress() ...@@ -22,11 +22,17 @@ LoadingProgress()
## 属性 ## 属性
除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| color | [ResourceColor](ts-types.md#resourcecolor) | 设置加载进度条前景色。<br/>默认值:'#99666666'。<br/>从API version 9开始,该接口支持在ArkTS卡片中使用。 | | color | [ResourceColor](ts-types.md#resourcecolor) | 设置加载进度条前景色。<br/>默认值:'#99666666'。<br/>从API version 9开始,该接口支持在ArkTS卡片中使用。 |
| enableLoading<sup>10+</sup> | boolean | 设置LoadingProgress动画显示或者不显示。<br/>默认值:true。<br/>**说明:**<br/> LoadingProgress动画不显示时,该组件依旧占位。<br/>通用属性Visibility.Hidden隐藏的是包括border、padding等整个组件范围,而enableLoading=false只隐藏LoadingProgress本身动画内容,不包括border等。| | enableLoading<sup>10+</sup> | boolean | 设置LoadingProgress动画显示或者不显示。<br/>默认值:true。<br/>**说明:**<br/> LoadingProgress动画不显示时,该组件依旧占位。<br/>通用属性Visibility.Hidden隐藏的是包括border、padding等整个组件范围,而enableLoading=false只隐藏LoadingProgress本身动画内容,不包括border等。|
## 事件
支持[通用事件](ts-universal-events-click.md)
## 示例 ## 示例
```ts ```ts
......
...@@ -26,13 +26,13 @@ PatternLock(controller?: PatternLockController) ...@@ -26,13 +26,13 @@ PatternLock(controller?: PatternLockController)
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| --------------- | ------------------------------------- | ------------------------------------------------------------ | | --------------- | ------------------------------------- | ------------------------------------------------------------ |
| sideLength | [Length](ts-types.md#length) | 设置组件的宽度和高度(宽高相同)。设置为0或负数等非法值时组件不显示。<br/>默认值:300vp | | sideLength | [Length](ts-types.md#length) | 设置组件的宽度和高度(宽高相同)。设置为0或负数时组件不显示。<br/>默认值:288vp |
| circleRadius | [Length](ts-types.md#length) | 设置宫格中圆点的半径。<br/>默认值:14vp | | circleRadius | [Length](ts-types.md#length) | 设置宫格中圆点的半径。设置为0或负数时取默认值。<br/>默认值:6vp |
| regularColor | [ResourceColor](ts-types.md#resourcecolor) | 设置宫格圆点在“未选中”状态的填充颜色。<br/>默认值:Color.Black | | regularColor | [ResourceColor](ts-types.md#resourcecolor) | 设置宫格圆点在“未选中”状态的填充颜色。<br/>默认值:Color.Black |
| selectedColor | [ResourceColor](ts-types.md#resourcecolor) | 设置宫格圆点在“选中”状态的填充颜色。<br/>默认值:Color.Black | | selectedColor | [ResourceColor](ts-types.md#resourcecolor) | 设置宫格圆点在“选中”状态的填充颜色。<br/>默认值:Color.Black |
| activeColor | [ResourceColor](ts-types.md#resourcecolor) | 设置宫格圆点在“激活”状态的填充颜色(“激活”状态为手指经过圆点但还未选中的状态)。<br/>默认值:Color.Black | | activeColor | [ResourceColor](ts-types.md#resourcecolor) | 设置宫格圆点在“激活”状态的填充颜色(“激活”状态为手指经过圆点但还未选中的状态)。<br/>默认值:Color.Black |
| pathColor | [ResourceColor](ts-types.md#resourcecolor) | 设置连线的颜色。<br/>默认值:Color.Blue | | pathColor | [ResourceColor](ts-types.md#resourcecolor) | 设置连线的颜色。<br/>默认值:Color.Blue |
| pathStrokeWidth | number&nbsp;\|&nbsp;string | 设置连线的宽度。设置为0或负数等非法值时连线不显示。<br/>默认值:34vp | | pathStrokeWidth | number&nbsp;\|&nbsp;string | 设置连线的宽度。设置为0或负数时连线不显示。<br/>默认值:12vp |
| autoReset | boolean | 设置在完成密码输入后再次在组件区域按下时是否重置组件状态。设置为true,完成密码输入后再次在组件区域按下时会重置组件状态(即清除之前输入的密码);反之若设置为false,则不会重置组件状态。<br/>默认值:true | | autoReset | boolean | 设置在完成密码输入后再次在组件区域按下时是否重置组件状态。设置为true,完成密码输入后再次在组件区域按下时会重置组件状态(即清除之前输入的密码);反之若设置为false,则不会重置组件状态。<br/>默认值:true |
## 事件 ## 事件
......
...@@ -48,7 +48,7 @@ Slider(options?: {value?: number, min?: number, max?: number, step?: number, sty ...@@ -48,7 +48,7 @@ Slider(options?: {value?: number, min?: number, max?: number, step?: number, sty
| selectedColor | [ResourceColor](ts-types.md#resourcecolor) | 设置滑轨的已滑动部分颜色。<br/>从API version 9开始,该接口支持在ArkTS卡片中使用。 | | selectedColor | [ResourceColor](ts-types.md#resourcecolor) | 设置滑轨的已滑动部分颜色。<br/>从API version 9开始,该接口支持在ArkTS卡片中使用。 |
| showSteps | boolean | 设置当前是否显示步长刻度值。<br/>默认值:false <br/>从API version 9开始,该接口支持在ArkTS卡片中使用。| | showSteps | boolean | 设置当前是否显示步长刻度值。<br/>默认值:false <br/>从API version 9开始,该接口支持在ArkTS卡片中使用。|
| showTips | value: boolean,<br/>content<sup>10+</sup>?: [ResourceStr](ts-types.md#resourcestr) | value:设置滑动时是否显示气泡提示。<br/>默认值:false <br/>content:设置气泡提示的文本内容,默认显示当前百分比。<br/>从API version 9开始,该接口支持在ArkTS卡片中使用。<br/>**说明:** <br/>当direction的值为Axis.Horizontal时,tip显示在滑块正上方。值为Axis.Vertical时,tip显示在滑块正左边。<br/>tip的绘制区域为Slider自身节点的overlay。<br/>Slider不设置边距或者边距比较小时,tip会被截断。| | showTips | value: boolean,<br/>content<sup>10+</sup>?: [ResourceStr](ts-types.md#resourcestr) | value:设置滑动时是否显示气泡提示。<br/>默认值:false <br/>content:设置气泡提示的文本内容,默认显示当前百分比。<br/>从API version 9开始,该接口支持在ArkTS卡片中使用。<br/>**说明:** <br/>当direction的值为Axis.Horizontal时,tip显示在滑块正上方。值为Axis.Vertical时,tip显示在滑块正左边。<br/>tip的绘制区域为Slider自身节点的overlay。<br/>Slider不设置边距或者边距比较小时,tip会被截断。|
| trackThickness | [Length](ts-types.md#length) | 设置滑轨的粗细。<br/>默认值:当参数style的值设置[SliderStyle](#sliderstyle枚举说明).OutSet 时为 4.0vp,[SliderStyle](#sliderstyle枚举说明).InSet时为20.0vp<br/>从APIversion9开始,该接口支持在ArkTS卡片中使用。<br/>**说明:** <br/>设置为小于0的值时,按默认值显示。 | | trackThickness | [Length](ts-types.md#length) | 设置滑轨的粗细。<br/>默认值:当参数style的值设置[SliderStyle](#sliderstyle枚举说明).OutSet 时为 4.0vp,[SliderStyle](#sliderstyle枚举说明).InSet时为20.0vp<br/>从APIversion9开始,该接口支持在ArkTS卡片中使用。<br/>**说明:** <br/>设置为小于等于0的值时,按默认值显示。 |
| blockBorderColor<sup>10+</sup> | [ResourceColor](ts-types.md#resourcecolor) | 设置滑块描边颜色。 | | blockBorderColor<sup>10+</sup> | [ResourceColor](ts-types.md#resourcecolor) | 设置滑块描边颜色。 |
| blockBorderWidth<sup>10+</sup> | [Length](ts-types.md#length) | 设置滑块描边粗细。 | | blockBorderWidth<sup>10+</sup> | [Length](ts-types.md#length) | 设置滑块描边粗细。 |
| stepColor<sup>10+</sup> | [ResourceColor](ts-types.md#resourcecolor) | 设置刻度颜色。 | | stepColor<sup>10+</sup> | [ResourceColor](ts-types.md#resourcecolor) | 设置刻度颜色。 |
......
...@@ -88,12 +88,16 @@ struct Index { ...@@ -88,12 +88,16 @@ struct Index {
getDataFromUdmfRetry(event: DragEvent, callback: (data: DragEvent)=>void) getDataFromUdmfRetry(event: DragEvent, callback: (data: DragEvent)=>void)
{ {
let records: Array<udmf.UnifiedRecord> = event.getData().getRecords(); let data = event.getData();
if (records.length !== 0) { if (!data) {
callback(event); return false;
return true;
} }
return false; let records: Array<udmf.UnifiedRecord> = data.getRecords();
if (!records || records.length <= 0) {
return false;
}
callback(event);
return true;
} }
getDataFromUdmf(event: DragEvent, callback: (data: DragEvent)=>void) getDataFromUdmf(event: DragEvent, callback: (data: DragEvent)=>void)
......
...@@ -2695,3 +2695,27 @@ ...@@ -2695,3 +2695,27 @@
**ACL使能**:FALSE **ACL使能**:FALSE
**起始版本**:10 **起始版本**:10
## ohos.permission.UNINSTALL_BUNDLE
允许应用卸载应用。
**权限级别**:system_core
**授权方式**:system_grant
**ACL使能**:TRUE
**起始版本**:10
## ohos.permission.RECOVER_BUNDLE
允许应用恢复预置应用。
**权限级别**:system_core
**授权方式**:system_grant
**ACL使能**:TRUE
**起始版本**:10
...@@ -402,6 +402,7 @@ ...@@ -402,6 +402,7 @@
- [异步并发概述](arkts-utils/async-concurrency-overview.md) - [异步并发概述](arkts-utils/async-concurrency-overview.md)
- [单次I/O任务开发指导](arkts-utils/single-io-development.md) - [单次I/O任务开发指导](arkts-utils/single-io-development.md)
- 使用多线程并发能力进行开发 - 使用多线程并发能力进行开发
- [多线程并发概述](arkts-utils/multi-thread-concurrency-overview.md)
- [TaskPool和Worker的对比](arkts-utils/taskpool-vs-worker.md) - [TaskPool和Worker的对比](arkts-utils/taskpool-vs-worker.md)
- [CPU密集型任务开发指导](arkts-utils/cpu-intensive-task-development.md) - [CPU密集型任务开发指导](arkts-utils/cpu-intensive-task-development.md)
- [I/O密集型任务开发指导](arkts-utils/io-intensive-task-development.md) - [I/O密集型任务开发指导](arkts-utils/io-intensive-task-development.md)
...@@ -510,6 +511,7 @@ ...@@ -510,6 +511,7 @@
- 相机最佳实践 - 相机最佳实践
- [拍照实现方案](media/camera-shooting-case.md) - [拍照实现方案](media/camera-shooting-case.md)
- [录像实现方案](media/camera-recording-case.md) - [录像实现方案](media/camera-recording-case.md)
- [性能提升方案(仅对系统应用开放)](media/camera-preformance-imporvement.md)
- 图片 - 图片
- [图片开发概述](media/image-overview.md) - [图片开发概述](media/image-overview.md)
- [图片解码](media/image-decoding.md) - [图片解码](media/image-decoding.md)
...@@ -545,9 +547,9 @@ ...@@ -545,9 +547,9 @@
- [Hap包签名工具指导](security/hapsigntool-guidelines.md) - [Hap包签名工具指导](security/hapsigntool-guidelines.md)
- [HarmonyAppProvision配置文件](security/app-provision-structure.md) - [HarmonyAppProvision配置文件](security/app-provision-structure.md)
- AI - AI
- [AI开发概述](./ai/ai-overview.md) - [AI开发概述](ai/ai-overview.md)
- [使用MindSpore Lite JS API开发AI应用](./ai/mindspore-guidelines-based-js.md) - [使用MindSpore Lite JS API开发AI应用](ai/mindspore-guidelines-based-js.md)
- [使用MindSpore Lite Native API开发AI应用](./ai/mindspore-guidelines-based-native.md) - [使用MindSpore Lite Native API开发AI应用](ai/mindspore-guidelines-based-native.md)
- 网络与连接 - 网络与连接
- 网络管理 - 网络管理
- [网络管理开发概述](connectivity/net-mgmt-overview.md) - [网络管理开发概述](connectivity/net-mgmt-overview.md)
...@@ -559,6 +561,7 @@ ...@@ -559,6 +561,7 @@
- [网络连接管理](connectivity/net-connection-manager.md) - [网络连接管理](connectivity/net-connection-manager.md)
- [MDNS管理](connectivity/net-mdns.md) - [MDNS管理](connectivity/net-mdns.md)
- [流量管理](connectivity/net-statistics.md) - [流量管理](connectivity/net-statistics.md)
- [VPN管理](connectivity/net-vpn.md)
- IPC与RPC通信 - IPC与RPC通信
- [IPC与RPC通信概述](connectivity/ipc-rpc-overview.md) - [IPC与RPC通信概述](connectivity/ipc-rpc-overview.md)
- [IPC与RPC通信开发指导](connectivity/ipc-rpc-development-guideline.md) - [IPC与RPC通信开发指导](connectivity/ipc-rpc-development-guideline.md)
...@@ -625,12 +628,12 @@ ...@@ -625,12 +628,12 @@
- [设置分布式文件数据等级](file-management/set-security-label.md) - [设置分布式文件数据等级](file-management/set-security-label.md)
- [跨设备文件访问](file-management/file-access-across-devices.md) - [跨设备文件访问](file-management/file-access-across-devices.md)
- 后台任务(Background Task)管理 - 后台任务(Background Task)管理
- [后台任务概述](task-management/background-task-overview.md) - [后台任务总体概述](task-management/background-task-overview.md)
- [短时任务](task-management/transient-task.md) - [短时任务](task-management/transient-task.md)
- [长时任务](task-management/continuous-task.md) - [长时任务](task-management/continuous-task.md)
- [延迟任务](task-management/work-scheduler.md) - [延迟任务](task-management/work-scheduler.md)
- [代理提醒](task-management/agent-powered-reminder.md) - [代理提醒](task-management/agent-powered-reminder.md)
- [能效资源申请(仅对系统特权应用开放)](task-management/efficiency-resource-request.md) - [能效资源申请(仅对系统特权应用开放)](task-management/efficiency-resource-request.md)
- 设备管理 - 设备管理
- USB服务 - USB服务
- [USB服务开发概述](device/usb-overview.md) - [USB服务开发概述](device/usb-overview.md)
...@@ -743,6 +746,8 @@ ...@@ -743,6 +746,8 @@
- [Neural Network Runtime对接AI推理框架开发指导](napi/neural-network-runtime-guidelines.md) - [Neural Network Runtime对接AI推理框架开发指导](napi/neural-network-runtime-guidelines.md)
- 内存管理 - 内存管理
- [Purgeable memory开发指导](napi/purgeable-memory-guidelines.md) - [Purgeable memory开发指导](napi/purgeable-memory-guidelines.md)
- 设备管理
- [USB DDK开发指导](napi/usb-ddk-guidelines.md)
- 工具 - 工具
- [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md) - [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md)
- 调试工具 - 调试工具
...@@ -1066,11 +1071,22 @@ ...@@ -1066,11 +1071,22 @@
- [@ohos.net.sharing (网络共享管理)](reference/apis/js-apis-net-sharing.md) - [@ohos.net.sharing (网络共享管理)](reference/apis/js-apis-net-sharing.md)
- [@ohos.net.socket (Socket连接)](reference/apis/js-apis-socket.md) - [@ohos.net.socket (Socket连接)](reference/apis/js-apis-socket.md)
- [@ohos.net.statistics (流量管理)](reference/apis/js-apis-net-statistics.md) - [@ohos.net.statistics (流量管理)](reference/apis/js-apis-net-statistics.md)
- [@ohos.net.vpn (VPN管理)](reference/apis/js-apis-net-vpn.md)
- [@ohos.net.webSocket (WebSocket连接)](reference/apis/js-apis-webSocket.md) - [@ohos.net.webSocket (WebSocket连接)](reference/apis/js-apis-webSocket.md)
- [@ohos.request (上传下载)](reference/apis/js-apis-request.md) - [@ohos.request (上传下载)](reference/apis/js-apis-request.md)
- 通信与连接 - 通信与连接
- [@ohos.bluetooth.a2dp(蓝牙a2dp模块)(推荐)](reference/apis/js-apis-bluetooth-a2dp.md)
- [@ohos.bluetooth.access(蓝牙access模块)(推荐)](reference/apis/js-apis-bluetooth-access.md)
- [@ohos.bluetooth.baseProfile(蓝牙baseProfile模块)(推荐)](reference/apis/js-apis-bluetooth-baseProfile.md)
- [@ohos.bluetooth.ble(蓝牙ble模块)(推荐)](reference/apis/js-apis-bluetooth-ble.md)
- [@ohos.bluetooth.connection(蓝牙connection模块)(推荐)](reference/apis/js-apis-bluetooth-connection.md)
- [@ohos.bluetooth.constant(蓝牙constant模块)(推荐)](reference/apis/js-apis-bluetooth-constant.md)
- [@ohos.bluetooth.hfp(蓝牙hfp模块)(推荐)](reference/apis/js-apis-bluetooth-hfp.md)
- [@ohos.bluetooth.hid(蓝牙hid模块)(推荐)](reference/apis/js-apis-bluetooth-hid.md)
- [@ohos.bluetooth.pan(蓝牙pan模块)(推荐)](reference/apis/js-apis-bluetooth-pan.md)
- [@ohos.bluetooth.socket(蓝牙socket模块)(推荐)](reference/apis/js-apis-bluetooth-socket.md)
- [@ohos.bluetooth (蓝牙)(待停用)](reference/apis/js-apis-bluetooth.md) - [@ohos.bluetooth (蓝牙)(待停用)](reference/apis/js-apis-bluetooth.md)
- [@ohos.bluetoothManager (蓝牙)(推荐)](reference/apis/js-apis-bluetoothManager.md) - [@ohos.bluetoothManager (蓝牙)(待停用)](reference/apis/js-apis-bluetoothManager.md)
- [@ohos.connectedTag (有源标签)](reference/apis/js-apis-connectedTag.md) - [@ohos.connectedTag (有源标签)](reference/apis/js-apis-connectedTag.md)
- [@ohos.nfc.cardEmulation (标准NFC-cardEmulation)](reference/apis/js-apis-cardEmulation.md) - [@ohos.nfc.cardEmulation (标准NFC-cardEmulation)](reference/apis/js-apis-cardEmulation.md)
- [@ohos.nfc.controller (标准NFC)](reference/apis/js-apis-nfcController.md) - [@ohos.nfc.controller (标准NFC)](reference/apis/js-apis-nfcController.md)
...@@ -1146,7 +1162,6 @@ ...@@ -1146,7 +1162,6 @@
- [@ohos.multimodalInput.touchEvent (触摸输入事件)](reference/apis/js-apis-touchevent.md) - [@ohos.multimodalInput.touchEvent (触摸输入事件)](reference/apis/js-apis-touchevent.md)
- [@ohos.multimodalInput.shortKey(快捷键)](reference/apis/js-apis-shortKey.md) - [@ohos.multimodalInput.shortKey(快捷键)](reference/apis/js-apis-shortKey.md)
- [@ohos.power (系统电源管理)](reference/apis/js-apis-power.md) - [@ohos.power (系统电源管理)](reference/apis/js-apis-power.md)
- [@ohos.resourceschedule.deviceStandby (设备待机模块)](reference/apis/js-apis-resourceschedule-deviceStandby.md)
- [@ohos.runningLock (Runninglock锁)](reference/apis/js-apis-runninglock.md) - [@ohos.runningLock (Runninglock锁)](reference/apis/js-apis-runninglock.md)
- [@ohos.sensor (传感器)](reference/apis/js-apis-sensor.md) - [@ohos.sensor (传感器)](reference/apis/js-apis-sensor.md)
- [@ohos.settings (设置数据项名称)](reference/apis/js-apis-settings.md) - [@ohos.settings (设置数据项名称)](reference/apis/js-apis-settings.md)
...@@ -1180,7 +1195,6 @@ ...@@ -1180,7 +1195,6 @@
- [@ohos.enterprise.EnterpriseAdminExtensionAbility (企业设备管理扩展能力)](reference/apis/js-apis-EnterpriseAdminExtensionAbility.md) - [@ohos.enterprise.EnterpriseAdminExtensionAbility (企业设备管理扩展能力)](reference/apis/js-apis-EnterpriseAdminExtensionAbility.md)
- [@ohos.enterprise.networkManager (网络管理)](reference/apis/js-apis-enterprise-networkManager.md) - [@ohos.enterprise.networkManager (网络管理)](reference/apis/js-apis-enterprise-networkManager.md)
- [@ohos.enterprise.restrictions (限制类策略)](reference/apis/js-apis-enterprise-restrictions.md) - [@ohos.enterprise.restrictions (限制类策略)](reference/apis/js-apis-enterprise-restrictions.md)
- [@ohos.enterprise.usbManager (USB管理)](reference/apis/js-apis-enterprise-usbManager.md)
- [@ohos.enterprise.wifiManager (WiFi管理)](reference/apis/js-apis-enterprise-wifiManager.md) - [@ohos.enterprise.wifiManager (WiFi管理)](reference/apis/js-apis-enterprise-wifiManager.md)
- 语言基础类库 - 语言基础类库
- [@ohos.buffer (Buffer)](reference/apis/js-apis-buffer.md) - [@ohos.buffer (Buffer)](reference/apis/js-apis-buffer.md)
...@@ -1390,6 +1404,7 @@ ...@@ -1390,6 +1404,7 @@
- [GridRow](reference/arkui-ts/ts-container-gridrow.md) - [GridRow](reference/arkui-ts/ts-container-gridrow.md)
- [Grid](reference/arkui-ts/ts-container-grid.md) - [Grid](reference/arkui-ts/ts-container-grid.md)
- [GridItem](reference/arkui-ts/ts-container-griditem.md) - [GridItem](reference/arkui-ts/ts-container-griditem.md)
- [Hyperlink](reference/arkui-ts/ts-container-hyperlink.md)
- [List](reference/arkui-ts/ts-container-list.md) - [List](reference/arkui-ts/ts-container-list.md)
- [ListItem](reference/arkui-ts/ts-container-listitem.md) - [ListItem](reference/arkui-ts/ts-container-listitem.md)
- [ListItemGroup](reference/arkui-ts/ts-container-listitemgroup.md) - [ListItemGroup](reference/arkui-ts/ts-container-listitemgroup.md)
...@@ -1439,6 +1454,7 @@ ...@@ -1439,6 +1454,7 @@
- [组件内转场](reference/arkui-ts/ts-transition-animation-component.md) - [组件内转场](reference/arkui-ts/ts-transition-animation-component.md)
- [共享元素转场](reference/arkui-ts/ts-transition-animation-shared-elements.md) - [共享元素转场](reference/arkui-ts/ts-transition-animation-shared-elements.md)
- [组件内隐式共享元素转场](reference/arkui-ts/ts-transition-animation-geometrytransition.md) - [组件内隐式共享元素转场](reference/arkui-ts/ts-transition-animation-geometrytransition.md)
- [路径动画](reference/arkui-ts/ts-motion-path-animation.md)
- 全局UI方法 - 全局UI方法
- 弹窗 - 弹窗
- [警告弹窗](reference/arkui-ts/ts-methods-alert-dialog-box.md) - [警告弹窗](reference/arkui-ts/ts-methods-alert-dialog-box.md)
...@@ -1456,7 +1472,7 @@ ...@@ -1456,7 +1472,7 @@
- 已停止维护的组件 - 已停止维护的组件
- [GridContainer](reference/arkui-ts/ts-container-gridcontainer.md) - [GridContainer](reference/arkui-ts/ts-container-gridcontainer.md)
- 已停止维护的接口 - 已停止维护的接口
- [点击控制](reference/arkui-ts/ts-universal-attributes-click.md) - [点击控制](reference/arkui-ts/ts-universal-attributes-click.md)
- 组件参考(兼容JS的类Web开发范式-ArkUI.Full) - 组件参考(兼容JS的类Web开发范式-ArkUI.Full)
- 组件通用信息 - 组件通用信息
- [通用属性](reference/arkui-js/js-components-common-attributes.md) - [通用属性](reference/arkui-js/js-components-common-attributes.md)
...@@ -1691,6 +1707,7 @@ ...@@ -1691,6 +1707,7 @@
- [策略管理错误码](reference/errorcodes/errorcode-net-policy.md) - [策略管理错误码](reference/errorcodes/errorcode-net-policy.md)
- [MDNS错误码](reference/errorcodes/errorcode-net-mdns.md) - [MDNS错误码](reference/errorcodes/errorcode-net-mdns.md)
- [流量管理错误码](reference/errorcodes/errorcode-net-statistics.md) - [流量管理错误码](reference/errorcodes/errorcode-net-statistics.md)
- [VPN错误码](reference/errorcodes/errorcode-net-vpn.md)
- 通信与连接 - 通信与连接
- [Bluetooth错误码](reference/errorcodes/errorcode-bluetoothManager.md) - [Bluetooth错误码](reference/errorcodes/errorcode-bluetoothManager.md)
- [WIFI错误码](reference/errorcodes/errorcode-wifi.md) - [WIFI错误码](reference/errorcodes/errorcode-wifi.md)
...@@ -1758,11 +1775,13 @@ ...@@ -1758,11 +1775,13 @@
- [AVDemuxer](reference/native-apis/_a_v_demuxer.md) - [AVDemuxer](reference/native-apis/_a_v_demuxer.md)
- [AVSource](reference/native-apis/_a_v_source.md) - [AVSource](reference/native-apis/_a_v_source.md)
- [OHAudio](reference/native-apis/_o_h_audio.md) - [OHAudio](reference/native-apis/_o_h_audio.md)
- [AVScreenCapture](reference/native-apis/_a_v_screen_capture.md)
- [HuksKeyApi](reference/native-apis/_huks_key_api.md) - [HuksKeyApi](reference/native-apis/_huks_key_api.md)
- [HuksParamSetApi](reference/native-apis/_huks_param_set_api.md) - [HuksParamSetApi](reference/native-apis/_huks_param_set_api.md)
- [HuksTypeApi](reference/native-apis/_huks_type_api.md) - [HuksTypeApi](reference/native-apis/_huks_type_api.md)
- [Init](reference/native-apis/init.md) - [Init](reference/native-apis/init.md)
- [Memory](reference/native-apis/memory.md) - [Memory](reference/native-apis/memory.md)
- [UsbDdk](reference/native-apis/_usb_ddk.md)
- [Hitrace](reference/native-apis/_hitrace.md) - [Hitrace](reference/native-apis/_hitrace.md)
- [Vulkan](reference/native-apis/_vulkan.md) - [Vulkan](reference/native-apis/_vulkan.md)
- 头文件 - 头文件
...@@ -1818,6 +1837,9 @@ ...@@ -1818,6 +1837,9 @@
- [native_audiorenderer.h](reference/native-apis/native__audiorenderer_8h.md) - [native_audiorenderer.h](reference/native-apis/native__audiorenderer_8h.md)
- [native_audiostream_base.h](reference/native-apis/native__audiostream__base_8h.md) - [native_audiostream_base.h](reference/native-apis/native__audiostream__base_8h.md)
- [native_audiostreambuilder.h](reference/native-apis/native__audiostreambuilder_8h.md) - [native_audiostreambuilder.h](reference/native-apis/native__audiostreambuilder_8h.md)
- [native_avscreen_capture.h](reference/native-apis/native__avscreen__capture_8h.md)
- [native_avscreen_capture_base.h](reference/native-apis/native__avscreen__capture__base_8h.md)
- [native_avscreen_capture_errors.h](reference/native-apis/native__avscreen__capture__errors_8h.md)
- [native_huks_api.h](reference/native-apis/native__huks__api_8h.md) - [native_huks_api.h](reference/native-apis/native__huks__api_8h.md)
- [native_huks_param.h](reference/native-apis/native__huks__param_8h.md) - [native_huks_param.h](reference/native-apis/native__huks__param_8h.md)
- [native_huks_type.h](reference/native-apis/native__huks__type_8h.md) - [native_huks_type.h](reference/native-apis/native__huks__type_8h.md)
...@@ -1829,6 +1851,8 @@ ...@@ -1829,6 +1851,8 @@
- [relational_store.h](reference/native-apis/relational__store_8h.md) - [relational_store.h](reference/native-apis/relational__store_8h.md)
- [syscap_ndk.h](reference/native-apis/syscap__ndk_8h.md) - [syscap_ndk.h](reference/native-apis/syscap__ndk_8h.md)
- [purgeable_memory.h](reference/native-apis/purgeable__memory_8h.md) - [purgeable_memory.h](reference/native-apis/purgeable__memory_8h.md)
- [usb_ddk_api.h](reference/native-apis/usb__ddk__api_8h.md)
- [usb_ddk_types.h](reference/native-apis/usb__ddk__types_8h.md)
- [trace.h](reference/native-apis/trace_8h.md) - [trace.h](reference/native-apis/trace_8h.md)
- [vulkan_ohos.h](reference/native-apis/vulkan__ohos_8h.md) - [vulkan_ohos.h](reference/native-apis/vulkan__ohos_8h.md)
- 结构体 - 结构体
...@@ -1873,6 +1897,17 @@ ...@@ -1873,6 +1897,17 @@
- [OH_AVRange](reference/native-apis/_o_h___a_v_range.md) - [OH_AVRange](reference/native-apis/_o_h___a_v_range.md)
- [OH_AudioCapturer_Callbacks_Struct](reference/native-apis/_o_h___audio_capturer___callbacks___struct.md) - [OH_AudioCapturer_Callbacks_Struct](reference/native-apis/_o_h___audio_capturer___callbacks___struct.md)
- [OH_AudioRenderer_Callbacks_Struct](reference/native-apis/_o_h___audio_renderer___callbacks___struct.md) - [OH_AudioRenderer_Callbacks_Struct](reference/native-apis/_o_h___audio_renderer___callbacks___struct.md)
- [OH_AudioBuffer](reference/native-apis/_o_h___audio_buffer.md)
- [OH_AudioCaptureInfo](reference/native-apis/_o_h___audio_capture_info.md)
- [OH_AudioEncInfo](reference/native-apis/_o_h___audio_enc_info.md)
- [OH_AudioInfo](reference/native-apis/_o_h___audio_info.md)
- [OH_AVScreenCaptureCallback](reference/native-apis/_o_h___a_v_screen_capture_callback.md)
- [OH_AVScreenCaptureConfig](reference/native-apis/_o_h___a_v_screen_capture_config.md)
- [OH_RecorderInfo](reference/native-apis/_o_h___recorder_info.md)
- [OH_Rect](reference/native-apis/_o_h___rect.md)
- [OH_VideoCaptureInfo](reference/native-apis/_o_h___video_capture_info.md)
- [OH_VideoEncInfo](reference/native-apis/_o_h___video_enc_info.md)
- [OH_VideoInfo](reference/native-apis/_o_h___video_info.md)
- [OH_Huks_Blob](reference/native-apis/_o_h___huks___blob.md) - [OH_Huks_Blob](reference/native-apis/_o_h___huks___blob.md)
- [OH_Huks_CertChain](reference/native-apis/_o_h___huks___cert_chain.md) - [OH_Huks_CertChain](reference/native-apis/_o_h___huks___cert_chain.md)
- [OH_Huks_KeyInfo](reference/native-apis/_o_h___huks___key_info.md) - [OH_Huks_KeyInfo](reference/native-apis/_o_h___huks___key_info.md)
...@@ -1891,6 +1926,17 @@ ...@@ -1891,6 +1926,17 @@
- [OH_Rdb_Store](reference/native-apis/_o_h___rdb___store.md) - [OH_Rdb_Store](reference/native-apis/_o_h___rdb___store.md)
- [OH_VBucket](reference/native-apis/_o_h___v_bucket.md) - [OH_VBucket](reference/native-apis/_o_h___v_bucket.md)
- [OH_VObject](reference/native-apis/_o_h___v_object.md) - [OH_VObject](reference/native-apis/_o_h___v_object.md)
- [UsbConfigDescriptor](reference/native-apis/_usb_config_descriptor.md)
- [UsbControlRequestSetup](reference/native-apis/_usb_control_request_setup.md)
- [UsbDdkConfigDescriptor](reference/native-apis/_usb_ddk_config_descriptor.md)
- [UsbDdkEndpointDescriptor](reference/native-apis/_usb_ddk_endpoint_descriptor.md)
- [UsbDdkInterface](reference/native-apis/_usb_ddk_interface.md)
- [UsbDdkInterfaceDescriptor](reference/native-apis/_usb_ddk_interface_descriptor.md)
- [UsbDeviceDescriptor](reference/native-apis/_usb_device_descriptor.md)
- [UsbDeviceMemMap](reference/native-apis/_usb_device_mem_map.md)
- [UsbEndpointDescriptor](reference/native-apis/_usb_endpoint_descriptor.md)
- [UsbInterfaceDescriptor](reference/native-apis/_usb_interface_descriptor.md)
- [UsbRequestPipe](reference/native-apis/_usb_request_pipe.md)
- [VkExternalFormatOHOS](reference/native-apis/_vk_external_format_o_h_o_s.md) - [VkExternalFormatOHOS](reference/native-apis/_vk_external_format_o_h_o_s.md)
- [VkImportNativeBufferInfoOHOS](reference/native-apis/_vk_import_native_buffer_info_o_h_o_s.md) - [VkImportNativeBufferInfoOHOS](reference/native-apis/_vk_import_native_buffer_info_o_h_o_s.md)
- [VkMemoryGetNativeBufferInfoOHOS](reference/native-apis/_vk_memory_get_native_buffer_info_o_h_o_s.md) - [VkMemoryGetNativeBufferInfoOHOS](reference/native-apis/_vk_memory_get_native_buffer_info_o_h_o_s.md)
......
# 分布式数据子系统ChangeLog
## cl.data.cloudData修改Action接口改名为clearAction
**变更影响**
基于OpenHarmony4.0.9.3及之后的SDK版本开发的应用,可以使用clearAction接口指定清除本地下载的云端数据的行为枚举。
**关键接口/组件变更**
修改前的接口原型:
```ts
enum Action {
CLEAR_CLOUD_INFO,
CLEAR_CLOUD_DATA_AND_INFO
}
```
修改后的接口原型:
```ts
enum ClearAction {
CLEAR_CLOUD_INFO,
CLEAR_CLOUD_DATA_AND_INFO
}
```
## cl.data.cloudData修改clean接口改名为clear
**变更影响**
基于OpenHarmony4.0.9.3及之后的SDK版本开发的应用,可以使用clear接口清除本地下载的云端数据。
**关键接口/组件变更**
修改前的接口原型:
```ts
static clean(
accountId: string,
appActions: { [bundleName: string]: Action },
callback: AsyncCallback<void>
): void;
static clean(accountId: string, appActions: { [bundleName: string]: Action }): Promise<void>;
```
修改后的接口原型:
```ts
static clear(
accountId: string,
appActions: { [bundleName: string]: ClearAction },
callback: AsyncCallback<void>
): void;
static clear(accountId: string, appActions: { [bundleName: string]: ClearAction }): Promise<void>;
```
## cl.data.relationalStore修改Statistic中的success为successful
**变更影响**
基于OpenHarmony4.0.9.3及之后的SDK版本开发的应用,可以使用Statistic.successful表示数据库表中端云同步成功的行数。
**关键接口/组件变更**
Statistic中的枚举项success变更为successful,successful表示数据库表中端云同步成功的行数。
修改前的接口原型:
```ts
interface Statistic {
total: number;
success: number;
failed: number;
remained: number;
}
```
修改后的接口原型:
```ts
interface Statistic {
total: number;
successful: number;
failed: number;
remained: number;
}
```
## cl.data.relationalStore修改setDistributedTables接口入参type类型由number变为DistributedType
**变更影响**
基于OpenHarmony4.0.9.3及之后的SDK版本开发的应用,setDistributedTables接口入参type类型由number变为DistributedType。
**关键接口/组件变更**
修改前setDistributedTables接口:
```ts
setDistributedTables(tables: Array<string>, type: number, config: DistributedConfig, callback: AsyncCallback<void>): void;
setDistributedTables(tables: Array<string>, type?: number, config?: DistributedConfig): Promise<void>;
```
修改后setDistributedTables接口:
```ts
setDistributedTables(tables: Array<string>, type: DistributedType, config: DistributedConfig, callback: AsyncCallback<void>): void;
setDistributedTables(tables: Array<string>, type?: DistributedType, config?: DistributedConfig): Promise<void>;
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册