Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
80b4197f
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
80b4197f
编写于
7月 01, 2022
作者:
L
lverpeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
删除分号
Signed-off-by:
N
lverpeng
<
lverpeng118@163.com
>
上级
a3a32941
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
159 addition
and
3 deletion
+159
-3
zh-cn/application-dev/reference/apis/js-apis-bluetooth.md
zh-cn/application-dev/reference/apis/js-apis-bluetooth.md
+159
-3
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-bluetooth.md
浏览文件 @
80b4197f
...
...
@@ -1039,9 +1039,9 @@ let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
## bluetooth.getProfile<sup>9+</sup><a name="getProfile"></a>
getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile | HidHostProfile
getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile | HidHostProfile
| PanProfile
通过ProfileId,获取profile的对象实例,API9新增了HidHostProfile。
通过ProfileId,获取profile的对象实例,API9新增了HidHostProfile
,PanProfile
。
**系统能力**
:SystemCapability.Communication.Bluetooth.Core。
...
...
@@ -1055,7 +1055,7 @@ getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfi
| 类型 | 说明 |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
|
[
A2dpSourceProfile
](
#A2dpSourceProfile
)
或
[
HandsFreeAudioGatewayProfile
](
#HandsFreeAudioGatewayProfile
)
或
[
HidHostProfile
](
#HidHostProfile
)
| 对应的profile的对象实例,当前支持A2dpSourceProfile/HandsFreeAudioGatewayProfile/HidHost
Profile。 |
|
[
A2dpSourceProfile
](
#A2dpSourceProfile
)
或
[
HandsFreeAudioGatewayProfile
](
#HandsFreeAudioGatewayProfile
)
或
[
HidHostProfile
](
#HidHostProfile
)
或
[
PanProfile
](
#PanProfile
)
| 对应的profile的对象实例,当前支持A2dpSourceProfile/HandsFreeAudioGatewayProfile/HidHostProfile/Pan
Profile。 |
**示例:**
...
...
@@ -1737,6 +1737,162 @@ hidHost.off('connectionStateChange', onReceiveEvent);
```
## PanProfile
使用PanProfile方法之前需要创建该类的实例进行操作,通过getProfile()方法构造此实例。
### disconnect<sup>9+</sup><a name="disconnect"></a>
disconnect(device: string): boolean
断开连接设备的Pan服务。
此接口为系统接口。
**需要权限**
:ohos.permission.USE_BLUETOOTH
**系统能力**
:SystemCapability.Communication.Bluetooth.Core。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------- |
| device | string | 是 | 远端设备地址。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | --------------------------------- |
| boolean | 成功返回true,失败返回false。 |
**示例:**
```
js
let
panProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
);
let
ret
=
panProfile
.
disconnect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
### on('connectionStateChange')<sup>9+</sup>
on(type: "connectionStateChange", callback: Callback
<
[StateChangeParam](#StateChangeParam)
>
): void
订阅Pan连接状态变化事件。
**系统能力**
:SystemCapability.Communication.Bluetooth.Core。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | 是 | 填写"connectionStateChange"字符串,表示连接状态变化事件。 |
| callback | Callback
<
[StateChangeParam](#StateChangeParam)
>
| 是 | 表示回调函数的入参。 |
**返回值:**
无
**示例:**
```
js
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
pan state =
'
+
JSON
.
stringify
(
data
));
}
let
panProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
);
panProfile
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
### off('connectionStateChange')<sup>9+</sup>
off(type: "connectionStateChange", callback?: Callback
<
[StateChangeParam](#StateChangeParam)
>
): void
取消订阅Pan连接状态变化事件。
**系统能力**
:SystemCapability.Communication.Bluetooth.Core。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- |
| type | string | 是 | 填写"connectionStateChange"字符串,表示连接状态变化事件。 |
| callback | Callback
<
[StateChangeParam](#StateChangeParam)
>
| 否 | 表示回调函数的入参。 |
**返回值:**
无
**示例:**
```
js
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
pan state =
'
+
JSON
.
stringify
(
data
));
}
let
panProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
);
panProfile
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
panProfile
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
### setTethering<sup>9+</sup><a name="setTethering"></a>
setTethering(value: boolean): boolean
设置网络共享状态。
此接口为系统接口。
**需要权限**
:ohos.permission.DISCOVER_BLUETOOTH
**系统能力**
:SystemCapability.Communication.Bluetooth.Core。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------- |
| value | boolean | 是 | 是否设置蓝牙共享。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | --------------------------------- |
| boolean | 成功返回true,失败返回false。 |
**示例:**
```
js
let
panProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
);
let
ret
=
panProfile
.
setTethering
(
true
);
```
### isTetheringOn<sup>9+</sup><a name="isTetheringOn"></a>
isTetheringOn(): boolean
获取网络共享状态。
此接口为系统接口。
**需要权限**
:ohos.permission.DISCOVER_BLUETOOTH
**系统能力**
:SystemCapability.Communication.Bluetooth.Core。
**返回值:**
| 类型 | 说明 |
| --------------------- | --------------------------------- |
| boolean | 网络共享开启返回true,网络共享关闭返回false。 |
**示例:**
```
js
let
panProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
);
let
ret
=
panProfile
.
isTetheringOn
();
```
## GattServer
server端类,使用server端方法之前需要创建该类的实例进行操作,通过createGattServer()方法构造此实例。
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录