提交 452a3167 编写于 作者: A Aurora 提交者: Gitee

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

Signed-off-by: NAurora <liuxiyao223@huawei.com>
...@@ -32,7 +32,7 @@ Then, equip yourself for developing the key features, with the following guideli ...@@ -32,7 +32,7 @@ Then, equip yourself for developing the key features, with the following guideli
- [WebGL](webgl/webgl-overview.md) - [WebGL](webgl/webgl-overview.md)
- [Media](media/media-application-overview.md) - [Media](media/media-application-overview.md)
- [Security](security/userauth-overview.md) - [Security](security/userauth-overview.md)
- [AI](ai/mindspore-lite-js-guidelines.md) - [AI](ai/ai-overview.md)
- [Connectivity](connectivity/ipc-rpc-overview.md) - [Connectivity](connectivity/ipc-rpc-overview.md)
- [Telephony Service](telephony/telephony-overview.md) - [Telephony Service](telephony/telephony-overview.md)
- [Data Management](database/data-mgmt-overview.md) - [Data Management](database/data-mgmt-overview.md)
......
...@@ -16,7 +16,7 @@ Widget-related configuration includes **FormExtensionAbility** configuration and ...@@ -16,7 +16,7 @@ Widget-related configuration includes **FormExtensionAbility** configuration and
"extensionAbilities": [ "extensionAbilities": [
{ {
"name": "EntryFormAbility", "name": "EntryFormAbility",
"srcEntry": "./ets/entryformability/EntryFormAbility.ts", "srcEntry": "./ets/entryformability/EntryFormAbility.ets",
"label": "$string:EntryFormAbility_label", "label": "$string:EntryFormAbility_label",
"description": "$string:EntryFormAbility_desc", "description": "$string:EntryFormAbility_desc",
"type": "form", "type": "form",
...@@ -42,9 +42,9 @@ Widget-related configuration includes **FormExtensionAbility** configuration and ...@@ -42,9 +42,9 @@ Widget-related configuration includes **FormExtensionAbility** configuration and
| description | Description of the widget. The value can be a string or a resource index to descriptions in multiple languages. The value is a string with a maximum of 255 bytes.| String| Yes (initial value: left empty)| | description | Description of the widget. The value can be a string or a resource index to descriptions in multiple languages. The value is a string with a maximum of 255 bytes.| String| Yes (initial value: left empty)|
| src | Full path of the UI code corresponding to the widget. For an ArkTS widget, the full path must contain the widget file name extension, for example, **./ets/widget/pages/WidgetCard.ets**. For a JS widget, the full path does not need to contain the widget file name extension, for example, **./js/widget/pages/WidgetCard**.| String| No| | src | Full path of the UI code corresponding to the widget. For an ArkTS widget, the full path must contain the widget file name extension, for example, **./ets/widget/pages/WidgetCard.ets**. For a JS widget, the full path does not need to contain the widget file name extension, for example, **./js/widget/pages/WidgetCard**.| String| No|
| uiSyntax | Type of the widget.<br>- **arkts**: ArkTS widget<br>- **hml**: JS widget| String| Yes (initial value: **hml**)| | uiSyntax | Type of the widget.<br>- **arkts**: ArkTS widget<br>- **hml**: JS widget| String| Yes (initial value: **hml**)|
| window | Window-related configurations.| Object| Yes| | window | Window-related configurations.| Object| YYes (initial value: see Table 2)|
| isDefault | Whether the widget is a default one. Each UIAbility has only one default widget.<br>- **true**: The widget is the default one.<br>- **false**: The widget is not the default one.| Boolean| No| | isDefault | Whether the widget is a default one. Each UIAbility has only one default widget.<br>- **true**: The widget is the default one.<br>- **false**: The widget is not the default one.| Boolean| No|
| colorMode | Color mode of the widget.<br>- **auto**: auto-adaptive color mode<br>- **dark**: dark color mode<br>- **light**: light color mode| String| Yes (initial value: **auto**)| | colorMode | Color mode of the widget.<br>- **auto**: following the system color mode<br>- **dark**: dark color mode<br>- **light**: light color mode| String| Yes (initial value: **auto**)|
| supportDimensions | Grid styles supported by the widget.<br>- **1 * 2**: indicates a grid with one row and two columns.<br>- **2 * 2**: indicates a grid with two rows and two columns.<br>- **2 * 4**: indicates a grid with two rows and four columns.<br>- **4 * 4**: indicates a grid with four rows and four columns.| String array| No| | supportDimensions | Grid styles supported by the widget.<br>- **1 * 2**: indicates a grid with one row and two columns.<br>- **2 * 2**: indicates a grid with two rows and two columns.<br>- **2 * 4**: indicates a grid with two rows and four columns.<br>- **4 * 4**: indicates a grid with four rows and four columns.| String array| No|
| defaultDimension | Default grid style of the widget. The value must be available in the **supportDimensions** array of the widget.| String| No| | defaultDimension | Default grid style of the widget. The value must be available in the **supportDimensions** array of the widget.| String| No|
| updateEnabled | Whether the widget can be updated periodically.<br>- **true**: The widget can be updated at a specified interval (**updateDuration**) or at the scheduled time (**scheduledUpdateTime**). **updateDuration** takes precedence over **scheduledUpdateTime**. If both are specified, the value specified by **updateDuration** is used.<br>- **false**: The widget cannot be updated periodically.| Boolean| No| | updateEnabled | Whether the widget can be updated periodically.<br>- **true**: The widget can be updated at a specified interval (**updateDuration**) or at the scheduled time (**scheduledUpdateTime**). **updateDuration** takes precedence over **scheduledUpdateTime**. If both are specified, the value specified by **updateDuration** is used.<br>- **false**: The widget cannot be updated periodically.| Boolean| No|
...@@ -56,6 +56,13 @@ Widget-related configuration includes **FormExtensionAbility** configuration and ...@@ -56,6 +56,13 @@ Widget-related configuration includes **FormExtensionAbility** configuration and
| dataProxyEnabled | Whether the widget supports the [update-through-proxy](./arkts-ui-widget-update-by-proxy.md) feature.<br>- **true**: The widget supports the update-through-proxy feature.<br>- **false**: The widget does not support the update-through-proxy feature.<br>If this tag is set to **true**, the settings for the scheduled update time will still take effect, but the settings for the update interval and next update time will not.| Boolean| Yes (initial value: **false**)| | dataProxyEnabled | Whether the widget supports the [update-through-proxy](./arkts-ui-widget-update-by-proxy.md) feature.<br>- **true**: The widget supports the update-through-proxy feature.<br>- **false**: The widget does not support the update-through-proxy feature.<br>If this tag is set to **true**, the settings for the scheduled update time will still take effect, but the settings for the update interval and next update time will not.| Boolean| Yes (initial value: **false**)|
| isDynamic | Whether the widget is a dynamic widget. This tag only applies to ArkTS widgets.<br>- **true**: The widget is a dynamic widget.<br>- **false**: The widget is a static widget. In this case, the widget is displayed as a static image after being added.| Boolean| Yes (initial value: **true**)| | isDynamic | Whether the widget is a dynamic widget. This tag only applies to ArkTS widgets.<br>- **true**: The widget is a dynamic widget.<br>- **false**: The widget is a static widget. In this case, the widget is displayed as a static image after being added.| Boolean| Yes (initial value: **true**)|
**Table 2** Internal structure of the window object
| Field| Description| Data Type| Default Value Allowed|
| -------- | -------- | -------- | -------- |
| designWidth | Baseline width for page design. The size of an element is scaled by the actual device width.| Number| Yes (initial value: **720px**)|
| autoDesignWidth | Whether to automatically calculate the baseline width for page design. If it is set to **true**, the **designWidth** attribute will be ignored, and the baseline width will be calculated based on the device width and screen density.| Boolean| Yes (initial value: **false**)|
Example configuration: Example configuration:
......
# Using Animations in the Widget # Using Animations in the Widget
To make your ArkTS widget more engaging, you can apply animations to it, including [explicit animation](../reference/arkui-ts/ts-explicit-animation.md), [attribute animation](../reference/arkui-ts/ts-animatorproperty.md), and [component transition](../reference/arkui-ts/ts-transition-animation-component.md). Just note the following restrictions when using the animations in ArkTS widgets. To make your ArkTS widget more engaging, you can apply animations to it, including [explicit animation](../reference/arkui-ts/ts-explicit-animation.md), [property animation](../reference/arkui-ts/ts-animatorproperty.md), and [component transition](../reference/arkui-ts/ts-transition-animation-component.md). Just note the following restrictions when using the animations in ArkTS widgets.
**Table 1** Restrictions on animation parameters **Table 1** Restrictions on animation parameters
......
...@@ -35,7 +35,7 @@ As a quick entry to applications, ArkTS widgets outperform JS widgets in the fol ...@@ -35,7 +35,7 @@ As a quick entry to applications, ArkTS widgets outperform JS widgets in the fol
![WidgetProject](figures/WidgetProject.png) ![WidgetProject](figures/WidgetProject.png)
- More widget features - More widget features
- Animation: ArkTS widgets support the [attribute animation](../reference/arkui-ts/ts-animatorproperty.md) and [explicit animation](../reference/arkui-ts/ts-explicit-animation.md) capabilities, which can be leveraged to deliver a more engaging experience. - Animation: ArkTS widgets support the [property animation](../reference/arkui-ts/ts-animatorproperty.md) and [explicit animation](../reference/arkui-ts/ts-explicit-animation.md) capabilities, which can be leveraged to deliver a more engaging experience.
- Custom drawing: ArkTS widgets allow you to draw graphics with the [\<Canvas>](../reference/arkui-ts/ts-components-canvas-canvas.md) component to present information more vividly. - Custom drawing: ArkTS widgets allow you to draw graphics with the [\<Canvas>](../reference/arkui-ts/ts-components-canvas-canvas.md) component to present information more vividly.
- Logic code execution: The capability to run logic code in widgets means that service logic can be self-closed in widgets, expanding the use cases of widgets. - Logic code execution: The capability to run logic code in widgets means that service logic can be self-closed in widgets, expanding the use cases of widgets.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
- [Full SDK Compilation](full-sdk-compile-guide.md) - [Full SDK Compilation](full-sdk-compile-guide.md)
- [Switching to Full SDK](full-sdk-switch-guide.md) - [Switching to Full SDK](full-sdk-switch-guide.md)
- [Using Native APIs (NDK) of the OpenHarmony SDK in a CMake Project](howto-migrate-cmake-with-ohosndk.md) - [Using Native APIs (NDK) of the OpenHarmony SDK in a CMake Project](cmake-with-ndk.md)
- [Application Model Development](faqs-ability.md) - [Application Model Development](faqs-ability.md)
- ArkUI Development (ArkTS) - ArkUI Development (ArkTS)
- [ArkTS Syntax Usage](faqs-arkui-arkts.md) - [ArkTS Syntax Usage](faqs-arkui-arkts.md)
......
...@@ -23,32 +23,37 @@ For details about the APIs, see [native_window](../reference/native-apis/_native ...@@ -23,32 +23,37 @@ For details about the APIs, see [native_window](../reference/native-apis/_native
The following describes how to use the native APIs provided by **NativeWindow** to request a graphics buffer, write the produced graphics content to the buffer, and flush the buffer to the graphics queue. The following describes how to use the native APIs provided by **NativeWindow** to request a graphics buffer, write the produced graphics content to the buffer, and flush the buffer to the graphics queue.
**Adding Dynamic Link Libraries**
Add the following libraries to **CMakeLists.txt**:
```txt
libace_ndk.z.so
libnative_window.so
```
**Header File** **Header File**
```c++ ```c++
#include <ace/xcomponent/native_interface_xcomponent.h>
#include <native_window/external_window.h> #include <native_window/external_window.h>
``` ```
1. Obtain an **OHNativeWindow** instance, which can be obtained by running the APIs provided by [OH_NativeXComponent_Callback](../reference/native-apis/_o_h___native_x_component___callback.md). 1. Obtain an **OHNativeWindow** instance.
1. Define **XComponent** in an .ets file.
You can call the APIs provided by [OH_NativeXComponent_Callback](../reference/native-apis/_o_h___native_x_component___callback.md) to obtain an **OHNativeWindow** instance. An example code snippet is provided below. For details about how to use the **\<XComponent>**, see [XComponent Development](xcomponent-guidelines.md).
1. Add an **\<XComponent>** to the .ets file.
```ts ```ts
XComponent({ id: 'xcomponentId', type: 'surface', libraryname: 'nativerender'}) XComponent({ id: 'xcomponentId', type: 'surface', libraryname: 'entry'})
.onLoad((context) => { .width(360)
this.context = context; .height(360)
})
.onDestroy(() => {
})
``` ```
2. Obtain **NativeXComponent** at the native C++ layer. 2. Obtain **NativeXComponent** at the native C++ layer.
```c++ ```c++
napi_value exportInstance = nullptr; napi_value exportInstance = nullptr;
// Parse the attribute of the wrapped NativeXComponent pointer.
napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance); napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
OH_NativeXComponent *nativeXComponent = nullptr; OH_NativeXComponent *nativeXComponent = nullptr;
// Use the napi_unwrap API to parse the NativeXComponent instance pointer.
napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent)); napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent));
char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = { };
uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize);
``` ```
3. Define **OH_NativeXComponent_Callback**. 3. Define **OH_NativeXComponent_Callback**.
```c++ ```c++
...@@ -56,48 +61,50 @@ The following describes how to use the native APIs provided by **NativeWindow** ...@@ -56,48 +61,50 @@ The following describes how to use the native APIs provided by **NativeWindow**
void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window) void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window)
{ {
// Obtain an OHNativeWindow instance. // Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = window; OHNativeWindow* nativeWindow = static_cast<OHNativeWindow*>(window);
// ... // ...
} }
void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window) void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window)
{ {
// Obtain an OHNativeWindow instance. // Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = window; OHNativeWindow* nativeWindow = static_cast<OHNativeWindow*>(window);
// ... // ...
} }
void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window)
{ {
// Obtain an OHNativeWindow instance. // Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = window; OHNativeWindow* nativeWindow = static_cast<OHNativeWindow*>(window);
// ... // ...
} }
void DispatchTouchEventCB(OH_NativeXComponent* component, void* window) void DispatchTouchEventCB(OH_NativeXComponent* component, void* window)
{ {
// Obtain an OHNativeWindow instance. // Obtain an OHNativeWindow instance.
OHNativeWindow* nativeWindow = window; OHNativeWindow* nativeWindow = static_cast<OHNativeWindow*>(window);
// ... // ...
} }
``` ```
```c++ ```c++
// Initialize OH_NativeXComponent_Callback. // Initialize OH_NativeXComponent_Callback.
OH_NativeXComponent_Callback callback_; OH_NativeXComponent_Callback callback;
callback_->OnSurfaceCreated = OnSurfaceCreatedCB; callback.OnSurfaceCreated = OnSurfaceCreatedCB;
callback_->OnSurfaceChanged = OnSurfaceChangedCB; callback.OnSurfaceChanged = OnSurfaceChangedCB;
callback_->OnSurfaceDestroyed = OnSurfaceDestroyedCB; callback.OnSurfaceDestroyed = OnSurfaceDestroyedCB;
callback_->DispatchTouchEvent = DispatchTouchEventCB; callback.DispatchTouchEvent = DispatchTouchEventCB;
``` ```
4. Register **OH_NativeXComponent_Callback** with **NativeXComponent**. 4. Register **OH_NativeXComponent_Callback** with **NativeXComponent**.
```c++ ```c++
OH_NativeXComponent_RegisterCallback(nativeXComponent, &callback_); // Register the callback.
OH_NativeXComponent_RegisterCallback(nativeXComponent, &callback);
``` ```
2. Set the attributes of an **OHNativeWindowBuffer** by using **OH_NativeWindow_NativeWindowHandleOpt**. 2. Set the attributes of an **OHNativeWindowBuffer** by using **OH_NativeWindow_NativeWindowHandleOpt**.
```c++ ```c++
// Set the width and height of the OHNativeWindowBuffer. // Set the width and height of the OHNativeWindowBuffer.
code = SET_BUFFER_GEOMETRY; int32_t code = SET_BUFFER_GEOMETRY;
int32_t width = 0x100; int32_t width = 0x100;
int32_t height = 0x100; int32_t height = 0x100;
ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, width, height); // The nativeWindow instance is obtained from the callback in the previous step.
int32_t ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, width, height);
// Set the step of the OHNativeWindowBuffer. // Set the step of the OHNativeWindowBuffer.
code = SET_STRIDE; code = SET_STRIDE;
int32_t stride = 0x8; int32_t stride = 0x8;
...@@ -109,18 +116,27 @@ The following describes how to use the native APIs provided by **NativeWindow** ...@@ -109,18 +116,27 @@ The following describes how to use the native APIs provided by **NativeWindow**
OHNativeWindowBuffer* buffer = nullptr; OHNativeWindowBuffer* buffer = nullptr;
int fenceFd; int fenceFd;
// Obtain the OHNativeWindowBuffer instance by calling OH_NativeWindow_NativeWindowRequestBuffer. // Obtain the OHNativeWindowBuffer instance by calling OH_NativeWindow_NativeWindowRequestBuffer.
OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow_, &buffer, &fenceFd); OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &buffer, &fenceFd);
// Obtain the buffer handle by calling OH_NativeWindow_GetNativeBufferHandleFromNative. // Obtain the buffer handle by calling OH_NativeWindow_GetBufferHandleFromNative.
BufferHandle* bufferHandle = OH_NativeWindow_GetNativeBufferHandleFromNative(buffer); BufferHandle* bufferHandle = OH_NativeWindow_GetBufferHandleFromNative(buffer);
```
4. Map memory.
```c++
#include <sys/mman.h>
// Use mmap() to obtain the memory virtual address of buffer handle.
void* mappedAddr = mmap(bufferHandle->virAddr, bufferHandle->size, PROT_READ | PROT_WRITE, MAP_SHARED, bufferHandle->fd, 0);
if (mappedAddr == MAP_FAILED) {
// mmap failed
}
``` ```
4. Write the produced content to the **OHNativeWindowBuffer**. 5. Write the produced content to the **OHNativeWindowBuffer**.
```c++ ```c++
auto image = static_cast<uint8_t *>(buffer->sfbuffer->GetVirAddr());
static uint32_t value = 0x00; static uint32_t value = 0x00;
value++; value++;
uint32_t *pixel = static_cast<uint32_t *>(mappedAddr); // Use the address obtained by mmap() to access the memory.
uint32_t *pixel = static_cast<uint32_t *>(image);
for (uint32_t x = 0; x < width; x++) { for (uint32_t x = 0; x < width; x++) {
for (uint32_t y = 0; y < height; y++) { for (uint32_t y = 0; y < height; y++) {
*pixel++ = value; *pixel++ = value;
...@@ -133,5 +149,15 @@ The following describes how to use the native APIs provided by **NativeWindow** ...@@ -133,5 +149,15 @@ The following describes how to use the native APIs provided by **NativeWindow**
// Set the refresh region. If Rect in Region is a null pointer or rectNumber is 0, all contents in the OHNativeWindowBuffer are changed. // Set the refresh region. If Rect in Region is a null pointer or rectNumber is 0, all contents in the OHNativeWindowBuffer are changed.
Region region{nullptr, 0}; Region region{nullptr, 0};
// Flush the buffer to the consumer through OH_NativeWindow_NativeWindowFlushBuffer, for example, by displaying it on the screen. // Flush the buffer to the consumer through OH_NativeWindow_NativeWindowFlushBuffer, for example, by displaying it on the screen.
OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow_, buffer, fenceFd, region); OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, buffer, fenceFd, region);
``` ```
6. Unmap memory.
```c++
// Unmap the memory when the memory is no longer required.
int result = munmap(mappedAddr, bufferHandle->size);
if (result == -1) {
// munmap failed
}
```
<!--no_check-->
\ No newline at end of file
...@@ -19,18 +19,21 @@ The environment requirements for the Neural Network Runtime are as follows: ...@@ -19,18 +19,21 @@ The environment requirements for the Neural Network Runtime are as follows:
- Development environment: Ubuntu 18.04 or later. - Development environment: Ubuntu 18.04 or later.
- Access device: a standard device running OpenHarmony. The built-in hardware accelerator driver has been connected to the Neural Network Runtime through an HDI API. - Access device: a standard device running OpenHarmony. The built-in hardware accelerator driver has been connected to the Neural Network Runtime through an HDI API.
The Neural Network Runtime is opened to external systems through OpenHarmony Native APIs. Therefore, you need to use the Native development suite of the OpenHarmony to compile Neural Network Runtime applications. You can download the **ohos-sdk** package of the corresponding version from [Daily Build](http://ci.openharmony.cn/dailys/dailybuilds) in the OpenHarmony community and then decompress the package to obtain the Native development suite of the corresponding platform. Take Linux as an example. The package of the Native development suite is named `native-linux-{version number}.zip`. The Neural Network Runtime is opened to external systems through OpenHarmony Native APIs. Therefore, you need to use the Native development suite of the OpenHarmony to compile Neural Network Runtime applications.
### Environment Setup ### Environment Setup
1. Start the Ubuntu server. 1. Start the Ubuntu server.
2. Copy the downloaded package of the Native development suite to the root directory of the current user. 2. Copy the package of the Native development suite to the root directory of the current user.
3. Decompress the package of the Native development suite. 3. Decompress the package of the Native development suite.
```shell ```shell
unzip native-linux-{version number}.zip unzip native-linux-{version number}.zip
``` ```
The directory structure after decompression is as follows. The content in the directory may vary depending on version iteration. Use the Native APIs of the latest version. The directory structure after decompression is as follows. The content in the directory may vary depending on version iteration. Use the Native APIs of the latest version.
```text ```text
native/ native/
─ ─ build // Cross-compilation toolchain ─ ─ build // Cross-compilation toolchain
...@@ -470,22 +473,19 @@ The development process of the Neural Network Runtime consists of three phases: ...@@ -470,22 +473,19 @@ The development process of the Neural Network Runtime consists of three phases:
> The IR graphs of the model need to be passed to the hardware driver layer, so that the HDI service compiles the IR graphs into a computing graph dedicated to hardware. The compilation process is time-consuming. The Neural Network Runtime supports the computing graph cache feature. It can cache the computing graphs compiled by the HDI service to the device storage. If the same model is compiled on the same acceleration chip next time, you can specify the cache path so that the Neural Network Runtime can directly load the computing graphs in the cache file, reducing the compilation time. > The IR graphs of the model need to be passed to the hardware driver layer, so that the HDI service compiles the IR graphs into a computing graph dedicated to hardware. The compilation process is time-consuming. The Neural Network Runtime supports the computing graph cache feature. It can cache the computing graphs compiled by the HDI service to the device storage. If the same model is compiled on the same acceleration chip next time, you can specify the cache path so that the Neural Network Runtime can directly load the computing graphs in the cache file, reducing the compilation time.
Check the cached files in the cache directory. Check the cached files in the cache directory.
```shell ```shell
ls /data/local/tmp ls /data/local/tmp
``` ```
The command output is as follows: The command output is as follows:
```text ```text
# 0.nncache cache_info.nncache # 0.nncache cache_info.nncache
``` ```
If the cache is no longer used, manually delete the cache files. If the cache is no longer used, manually delete the cache files.
```shell ```shell
rm /data/local/tmp/*nncache rm /data/local/tmp/*nncache
``` ```
\ No newline at end of file
## Samples
The following sample is provided to help you understand how to connect a third-party AI inference framework to the Neural Network Runtime:
- [Development Guide for Connecting TensorFlow Lite to NNRt Delegate](https://gitee.com/openharmony/neural_network_runtime/tree/master/example/deep_learning_framework)
<!--no_check-->
此差异已折叠。
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
- Getting Started - Getting Started
- [Before You Start](start-overview.md) - [Before You Start](start-overview.md)
- [Getting Started with ArkTS in Stage Model](start-with-ets-stage.md) - [Building the First ArkTS Application in Stage Model](start-with-ets-stage.md)
- Development Fundamentals - Development Fundamentals
- Application Package Fundamentals - Application Package Fundamentals
- [Application Package Overview](application-package-overview.md) - [Application Package Overview](application-package-overview.md)
...@@ -41,8 +41,8 @@ ...@@ -41,8 +41,8 @@
- [Resource Categories and Access](resource-categories-and-access.md) - [Resource Categories and Access](resource-categories-and-access.md)
- Learning ArkTS - Learning ArkTS
- [Getting Started with ArkTS](arkts-get-started.md) - [Getting Started with ArkTS](arkts-get-started.md)
- [Introduction to ArkTS](arkts/introduction-to-arkts.md) - [Introduction to ArkTS](introduction-to-arkts.md)
- [TypeScript to ArkTS Migration Guide](arkts/typescript-to-arkts-migration-guide.md) - [TypeScript to ArkTS Migration Guide](typescript-to-arkts-migration-guide.md)
- UI paradigms - UI paradigms
- Basic Syntax - Basic Syntax
- [Basic Syntax Overview](arkts-basic-syntax-overview.md) - [Basic Syntax Overview](arkts-basic-syntax-overview.md)
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
- [\@Styles Decorator: Definition of Resusable Styles](arkts-style.md) - [\@Styles Decorator: Definition of Resusable Styles](arkts-style.md)
- [\@Extend Decorator: Extension of Built-in Components](arkts-extend.md) - [\@Extend Decorator: Extension of Built-in Components](arkts-extend.md)
- [stateStyles Decorator: Polymorphic Style](arkts-statestyles.md) - [stateStyles Decorator: Polymorphic Style](arkts-statestyles.md)
- [\@AnimatableExtend Decorator: Definition of Animatable Attributes](arkts-animatable-extend.md)
- State Management - State Management
- [State Management Overview](arkts-state-management-overview.md) - [State Management Overview](arkts-state-management-overview.md)
- Component State Management - Component State Management
......
...@@ -93,7 +93,6 @@ As shown above, the **module.json5** file contains several tags. ...@@ -93,7 +93,6 @@ As shown above, the **module.json5** file contains several tags.
| [dependencies](#dependencies)| List of shared libraries on which the current module depends during running.| Object array| Yes (initial value: left empty) | | [dependencies](#dependencies)| List of shared libraries on which the current module depends during running.| Object array| Yes (initial value: left empty) |
| targetModuleName | Target module of the bundle. The value is a string with a maximum of 31 bytes. It must be unique in the entire application.|String|Yes (if the initial value is used, the target module is not a module with the overlay feature)| | targetModuleName | Target module of the bundle. The value is a string with a maximum of 31 bytes. It must be unique in the entire application.|String|Yes (if the initial value is used, the target module is not a module with the overlay feature)|
| targetPriority | Priority of the module. When **targetModuleName** is set, the module is a module with the overlay feature. The value ranges from 1 to 100.|Number|Yes (initial value: **1**)| | targetPriority | Priority of the module. When **targetModuleName** is set, the module is a module with the overlay feature. The value ranges from 1 to 100.|Number|Yes (initial value: **1**)|
| [proxyDatas<sup>(deprecated)</sup>](#proxydatasdeprecated) | This API is deprecated since API version 10. You are advised to use **proxydata** instead. List of data proxies provided by the module.| Object array| Yes (initial value: left empty)|
| [proxyData](#proxydata) | List of data proxies provided by the module.| Object array| Yes (initial value: left empty)| | [proxyData](#proxydata) | List of data proxies provided by the module.| Object array| Yes (initial value: left empty)|
| isolationMode | Multi-process configuration of the module. The options are as follows:<br>- **nonisolationFirst**: The module preferentially runs in a non-independent process.<br>- **isolationFirst**: The module preferentially runs in an independent process.<br>- **isolationOnly**: The module runs only in an independent process.<br>- **nonisolationOnly**: The module runs only in non-independent processes.|String|Yes (initial value: **nonisolationFirst**)| | isolationMode | Multi-process configuration of the module. The options are as follows:<br>- **nonisolationFirst**: The module preferentially runs in a non-independent process.<br>- **isolationFirst**: The module preferentially runs in an independent process.<br>- **isolationOnly**: The module runs only in an independent process.<br>- **nonisolationOnly**: The module runs only in non-independent processes.|String|Yes (initial value: **nonisolationFirst**)|
| generateBuildHash |Whether the hash value of the HAP or HSP file is generated by the packaging tool. The hash value (if any) is used to determine whether the application needs to be updated when the system is updated in OTA mode but the **versionCode** value of the application remains unchanged.<br>This tag is enabled only when the **generateBuildHash** tag in the [app.json5](./app-configuration-file.md) file is **false**.**<br>**NOTE**<br>This tag applies only to system applications.**|Boolean|Yes (initial value: **false**)| | generateBuildHash |Whether the hash value of the HAP or HSP file is generated by the packaging tool. The hash value (if any) is used to determine whether the application needs to be updated when the system is updated in OTA mode but the **versionCode** value of the application remains unchanged.<br>This tag is enabled only when the **generateBuildHash** tag in the [app.json5](./app-configuration-file.md) file is **false**.**<br>**NOTE**<br>This tag applies only to system applications.**|Boolean|Yes (initial value: **false**)|
...@@ -421,7 +420,7 @@ Example of the **extensionAbilities** structure: ...@@ -421,7 +420,7 @@ Example of the **extensionAbilities** structure:
## requestPermissions ## requestPermissions
The **requestPermissions** tag represents a set of permissions that the application needs to request from the system for running correctly. The **requestPermissions** tag represents a set of permissions that the application needs to request from the system for running correctly. For details about how to request permissions, see [Applying for Permissions](../security/accesstoken-guidelines.md).
> **NOTE** > **NOTE**
> >
...@@ -738,40 +737,6 @@ Example of the **dependencies** structure: ...@@ -738,40 +737,6 @@ Example of the **dependencies** structure:
} }
``` ```
## proxyDatas<sup>(deprecated)</sup>
>This API is supported since API version 10 and deprecated since API version 10. You are advised to use [proxyData](#proxydata) instead.
The **proxyDatas** tag provides the list of data proxies provided by the module. It can be configured only for entry and feature modules.
**Table 21** proxyDatas
| Name | Description | Data Type| Initial Value Allowed|
| ----------- | ------------------------------ | -------- | ---------- |
| uri | URI of the data proxy. The URIs configured for different data proxies must be unique and must be in the *datashareproxy://Current application package name/xxx* format. | String | No|
| requiredReadPermission | Permission required for reading data from the data proxy. For non-system applications, this field is mandatory, and the permission level must be system_basic or system_core. For system applications, this field is optional, and the permission level is not limited. For details about the permission level, see [Application Permission List](../security/permission-list.md).| String | Yes (initial value: left empty)|
| requiredWritePermission | Permission required for writing data to the data proxy. For non-system applications, this field is mandatory, and the permission level must be system_basic or system_core. For system applications, this field is optional, and the permission level is not limited. For details about the permission level, see [Application Permission List](../security/permission-list.md).| String | Yes (initial value: left empty)|
| [metadata](#metadata)| Metadata of the data proxy. Only the **name** and **resource** fields can be configured.| Object| Yes (initial value: left empty)|
Example of the **proxyDatas** structure:
```json
{
"module": {
"proxyDatas": [
{
"uri":"datashareproxy://com.ohos.datashare/event/Meeting",
"requiredReadPermission": "ohos.permission.GET_BUNDLE_INFO",
"requiredWritePermission": "ohos.permission.GET_BUNDLE_INFO",
"metadata": {
"name": "datashare_metadata",
"resource": "$profile:datashare"
}
}
]
}
}
```
## proxyData ## proxyData
The **proxyDatas** tag provides the list of data proxies provided by the module. It can be configured only for entry and feature modules. The **proxyDatas** tag provides the list of data proxies provided by the module. It can be configured only for entry and feature modules.
...@@ -780,8 +745,8 @@ The **proxyDatas** tag provides the list of data proxies provided by the module. ...@@ -780,8 +745,8 @@ The **proxyDatas** tag provides the list of data proxies provided by the module.
| Name | Description | Data Type| Initial Value Allowed| | Name | Description | Data Type| Initial Value Allowed|
| ----------- | ------------------------------ | -------- | ---------- | | ----------- | ------------------------------ | -------- | ---------- |
| uri | URI of the data proxy. The URIs configured for different data proxies must be unique and must be in the *datashareproxy://Current application package name/xxx* format. | String | No| | uri | URI of the data proxy. The URIs configured for different data proxies must be unique and must be in the *datashareproxy://Current application package name/xxx* format. | String | No|
| requiredReadPermission | Permission required for reading data from the data proxy. For non-system applications, this field is mandatory, and the permission level must be system_basic or system_core. For system applications, this field is optional, and the permission level is not limited. For details about the permission level, see [Application Permission List](../security/permission-list.md).| String | Yes (initial value: left empty)| | requiredReadPermission | Permission required for reading data from the data proxy. If it is not specified, other applications will not be able to use the data proxy. For non-system applications, the level of the set permission must be system_basic or system_core. For system applications, the permission level is not limited. For details about the permission level, see [Application Permission List](../security/permission-list.md).| String | Yes (initial value: left empty)|
| requiredWritePermission | Permission required for writing data to the data proxy. For non-system applications, this field is mandatory, and the permission level must be system_basic or system_core. For system applications, this field is optional, and the permission level is not limited. For details about the permission level, see [Application Permission List](../security/permission-list.md).| String | Yes (initial value: left empty)| | requiredWritePermission | Permission required for writing data to the data proxy. If it is not specified, other applications will not be able to use the data proxy. For non-system applications, the level of the set permission must be system_basic or system_core. For system applications, the permission level is not limited. For details about the permission level, see [Application Permission List](../security/permission-list.md).| String | Yes (initial value: left empty)|
| [metadata](#metadata)| Metadata of the data proxy. Only the **name** and **resource** fields can be configured.| Object| Yes (initial value: left empty)| | [metadata](#metadata)| Metadata of the data proxy. Only the **name** and **resource** fields can be configured.| Object| Yes (initial value: left empty)|
Example of the **proxyData** structure: Example of the **proxyData** structure:
......
...@@ -44,4 +44,4 @@ To help you better understand the preceding basic concepts and application devel ...@@ -44,4 +44,4 @@ To help you better understand the preceding basic concepts and application devel
2. Install DevEco Studio and configure the development environment. For details, see [Setting Up the Development Environment](https://developer.harmonyos.com/en/docs/documentation/doc-guides-V3/environment_config-0000001052902427-V3). 2. Install DevEco Studio and configure the development environment. For details, see [Setting Up the Development Environment](https://developer.harmonyos.com/en/docs/documentation/doc-guides-V3/environment_config-0000001052902427-V3).
When you are done, follow the instructions in [Getting Started with ArkTS in Stage Model](start-with-ets-stage.md). When you are done, you can set out to [build your first ArkTS application in the stage model](start-with-ets-stage.md).
# Getting Started with ArkTS in Stage Model # Building the First ArkTS Application in Stage Model
> **NOTE** > **NOTE**
......
...@@ -317,8 +317,18 @@ ...@@ -317,8 +317,18 @@
- [@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)
......
...@@ -646,7 +646,7 @@ This is a system API. ...@@ -646,7 +646,7 @@ This is a system API.
```ts ```ts
let bundleName = "com.example.myapplication"; let bundleName = "com.example.myapplication";
bundleManager.setApplicationEnabled(bundleName, false).then(()=> { bundle.setApplicationEnabled(bundleName, false).then(()=> {
console.info('setApplicationEnabled successfully.'); console.info('setApplicationEnabled successfully.');
}).catch(err=> { }).catch(err=> {
console.error('setApplicationEnabled failed.'); console.error('setApplicationEnabled failed.');
...@@ -767,7 +767,7 @@ This is a system API. ...@@ -767,7 +767,7 @@ This is a system API.
```ts ```ts
let permission = "ohos.permission.GET_BUNDLE_INFO"; let permission = "ohos.permission.GET_BUNDLE_INFO";
bundleManager.getPermissionDef(permission, (err, data) => { bundle.getPermissionDef(permission, (err, data) => {
if (err) { if (err) {
console.error('getPermissionDef failed:' + err.message); console.error('getPermissionDef failed:' + err.message);
} else { } else {
......
# @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.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);
}
```
...@@ -9,7 +9,7 @@ The **BusinessAbilityInfo** module provides basic information about a business a ...@@ -9,7 +9,7 @@ The **BusinessAbilityInfo** module provides basic information about a business a
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| --------------------------------- | ------------------------------------------------------------ | ---- | ---- | -------------------- | | --------------------------------- | ------------------------------------------------------------ | ---- | ---- | -------------------- |
......
...@@ -61,7 +61,7 @@ Subscribes to bundle installation, uninstall, and update events. ...@@ -61,7 +61,7 @@ Subscribes to bundle installation, uninstall, and update events.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------------------------- | -------- | ---- | ------------------ | | ---------------------------- | -------- | ---- | ------------------ |
| type| [BundleChangedEvent](js-apis-bundleMonitor.md#BundleChangedEvent)| Yes | Type of the event to subscribe to.| | type| [BundleChangedEvent](js-apis-bundleMonitor.md#bundlechangedevent)| Yes | Type of the event to subscribe to.|
| callback | callback\<BundleChangedInfo>| Yes | Callback used for the subscription.| | callback | callback\<BundleChangedInfo>| Yes | Callback used for the subscription.|
**Example** **Example**
...@@ -94,7 +94,7 @@ Unsubscribes from bundle installation, uninstall, and update events. ...@@ -94,7 +94,7 @@ Unsubscribes from bundle installation, uninstall, and update events.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------------------------- | -------- | ---- | ---------------------------------------------------------- | | ---------------------------- | -------- | ---- | ---------------------------------------------------------- |
| type| [BundleChangedEvent](js-apis-bundleMonitor.md#BundleChangedEvent)| Yes | Type of the event to unsubscribe from. | | type| [BundleChangedEvent](js-apis-bundleMonitor.md#bundlechangedevent)| Yes | Type of the event to unsubscribe from. |
| callback | callback\<BundleChangedInfo>| No | Callback used for the unsubscription. By default, no value is passed, and all callbacks of the current event are unsubscribed from.| | callback | callback\<BundleChangedInfo>| No | Callback used for the unsubscription. By default, no value is passed, and all callbacks of the current event are unsubscribed from.|
**Example** **Example**
......
...@@ -22,7 +22,7 @@ SystemCapability.BundleManager.DistributedBundleFramework ...@@ -22,7 +22,7 @@ SystemCapability.BundleManager.DistributedBundleFramework
| Permission | Permission Level | Description | | Permission | Permission Level | Description |
| ------------------------------------------ | ------------ | ------------------ | | ------------------------------------------ | ------------ | ------------------ |
| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all bundles.| | ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to obtain basic information and other sensitive information about a bundle.|
For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels). For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
......
...@@ -244,7 +244,7 @@ Decompresses a file. This API uses an asynchronous callback to return the result ...@@ -244,7 +244,7 @@ Decompresses a file. This API uses an asynchronous callback to return the result
For details about the error codes, see [zlib Error Codes](../errorcodes/errorcode-zlib.md). For details about the error codes, see [zlib Error Codes](../errorcodes/errorcode-zlib.md).
| ID| Error Message | ID| Error Message |
| -------- | --------------------------------------| | -------- | --------------------------------------|
| 900001 | The input source file is invalid. | | 900001 | The input source file is invalid. |
| 900002 | The input destination file is invalid. | | 900002 | The input destination file is invalid. |
......
...@@ -164,8 +164,8 @@ ...@@ -164,8 +164,8 @@
- Advanced Components - Advanced Components
- [@ohos.multimedia.avCastPicker (AVCastPicker)](ohos-multimedia-avcastpicker.md) - [@ohos.multimedia.avCastPicker (AVCastPicker)](ohos-multimedia-avcastpicker.md)
- Animation - Animation
- [AnimatorProperty](ts-animatorproperty.md) - [Property Animation](ts-animatorproperty.md)
- [Explicit Animatio](ts-explicit-animation.md) - [Explicit Animation](ts-explicit-animation.md)
- Transition Animation - Transition Animation
- [Page Transition](ts-page-transition-animation.md) - [Page Transition](ts-page-transition-animation.md)
- [Component Transition](ts-transition-animation-component.md) - [Component Transition](ts-transition-animation-component.md)
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册