Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
d355bc5c
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看板
未验证
提交
d355bc5c
编写于
9月 29, 2022
作者:
O
openharmony_ci
提交者:
Gitee
9月 29, 2022
浏览文件
操作
浏览文件
下载
差异文件
!10064 蓝牙docs修复系统接口标识及部分示例代码问题
Merge pull request !10064 from huxiaokai/master
上级
12cb1f49
2a7e14cc
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
35 addition
and
31 deletion
+35
-31
zh-cn/application-dev/reference/apis/js-apis-bluetooth.md
zh-cn/application-dev/reference/apis/js-apis-bluetooth.md
+35
-31
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-bluetooth.md
浏览文件 @
d355bc5c
...
...
@@ -223,7 +223,7 @@ cancelPairedDevice(deviceId: string): boolean
删除配对的远程设备。
此接口为系统接口。
**系统接口**
:
此接口为系统接口。
**需要权限**
:ohos.permission.DISCOVER_BLUETOOTH
...
...
@@ -1293,7 +1293,7 @@ getConnectionDevices(): Array<string>
**示例:**
```
js
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
)
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
)
as
bluetooth
.
A2dpSourceProfile
;
let
retArray
=
a2dpSrc
.
getConnectionDevices
();
```
...
...
@@ -1322,7 +1322,7 @@ getDeviceState(device: string): ProfileConnectionState
**示例:**
```
js
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
)
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
)
as
bluetooth
.
A2dpSourceProfile
;
let
ret
=
a2dpSrc
.
getDeviceState
(
'
XX:XX:XX:XX:XX:XX
'
);
```
...
...
@@ -1356,7 +1356,7 @@ connect(device: string): boolean
**示例:**
```
js
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
)
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
)
as
bluetooth
.
A2dpSourceProfile
;
let
ret
=
a2dpSrc
.
connect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
...
...
@@ -1386,7 +1386,7 @@ disconnect(device: string): boolean
**示例:**
```
js
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
);
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
)
as
bluetooth
.
A2dpSourceProfile
;
let
ret
=
a2dpSrc
.
disconnect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
...
...
@@ -1416,7 +1416,7 @@ on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Stat
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
a2dp state =
'
+
JSON
.
stringify
(
data
));
}
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
);
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
)
as
bluetooth
.
A2dpSourceProfile
;
a2dpSrc
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
...
...
@@ -1446,7 +1446,7 @@ off(type: "connectionStateChange", callback?: Callback<[StateChangeParam](#St
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
a2dp state =
'
+
JSON
.
stringify
(
data
));
}
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
);
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
)
as
bluetooth
.
A2dpSourceProfile
;
a2dpSrc
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
a2dpSrc
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
...
...
@@ -1475,7 +1475,7 @@ getPlayingState(device: string): PlayingState
**示例:**
```
js
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
);
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
)
as
bluetooth
.
A2dpSourceProfile
;
let
state
=
a2dpSrc
.
getPlayingState
(
'
XX:XX:XX:XX:XX:XX
'
);
```
...
...
@@ -1510,7 +1510,8 @@ connect(device: string): boolean
**示例:**
```
js
let
hfpAg
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HANDS_FREE_AUDIO_GATEWAY
);
let
hfpAg
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HANDS_FREE_AUDIO_GATEWAY
)
as
bluetooth
.
HandsFreeAudioGatewayProfile
;
let
ret
=
hfpAg
.
connect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
...
...
@@ -1540,7 +1541,8 @@ disconnect(device: string): boolean
**示例:**
```
js
let
hfpAg
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HANDS_FREE_AUDIO_GATEWAY
);
let
hfpAg
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HANDS_FREE_AUDIO_GATEWAY
)
as
bluetooth
.
HandsFreeAudioGatewayProfile
;
let
ret
=
hfpAg
.
disconnect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
...
...
@@ -1570,7 +1572,8 @@ on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Stat
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
hfp state =
'
+
JSON
.
stringify
(
data
));
}
let
hfpAg
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HANDS_FREE_AUDIO_GATEWAY
);
let
hfpAg
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HANDS_FREE_AUDIO_GATEWAY
)
as
bluetooth
.
HandsFreeAudioGatewayProfile
;
hfpAg
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
...
...
@@ -1600,7 +1603,8 @@ off(type: "connectionStateChange", callback?: Callback<[StateChangeParam](#St
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
hfp state =
'
+
JSON
.
stringify
(
data
));
}
let
hfpAg
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HANDS_FREE_AUDIO_GATEWAY
);
let
hfpAg
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HANDS_FREE_AUDIO_GATEWAY
)
as
bluetooth
.
HandsFreeAudioGatewayProfile
;
hfpAg
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
hfpAg
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
...
...
@@ -1617,7 +1621,7 @@ connect(device: string): boolean
连接设备的HidHost服务。
此接口为系统接口。
**系统接口**
:
此接口为系统接口。
**需要权限**
:ohos.permission.DISCOVER_BLUETOOTH
...
...
@@ -1638,7 +1642,7 @@ connect(device: string): boolean
**示例:**
```
js
let
hidHostProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
)
;
let
hidHostProfile
=
bluetooth
.
getProfile
Inst
(
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
)
as
bluetooth
.
HidHostProfile
;
let
ret
=
hidHostProfile
.
connect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
...
...
@@ -1649,7 +1653,7 @@ disconnect(device: string): boolean
断开连接设备的HidHost服务。
此接口为系统接口。
**系统接口**
:
此接口为系统接口。
**需要权限**
:ohos.permission.DISCOVER_BLUETOOTH
...
...
@@ -1670,7 +1674,7 @@ disconnect(device: string): boolean
**示例:**
```
js
let
hidHostProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
)
;
let
hidHostProfile
=
bluetooth
.
getProfile
Inst
(
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
)
as
bluetooth
.
HidHostProfile
;
let
ret
=
hidHostProfile
.
disconnect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
...
...
@@ -1700,7 +1704,7 @@ on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Stat
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
hidHost state =
'
+
JSON
.
stringify
(
data
));
}
let
hidHost
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
)
;
let
hidHost
=
bluetooth
.
getProfile
Inst
(
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
)
as
bluetooth
.
HidHostProfile
;
hidHost
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
...
...
@@ -1730,7 +1734,7 @@ off(type: "connectionStateChange", callback?: Callback<[StateChangeParam](#St
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
hidHost state =
'
+
JSON
.
stringify
(
data
));
}
let
hidHost
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
)
;
let
hidHost
=
bluetooth
.
getProfile
Inst
(
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
)
as
bluetooth
.
HidHostProfile
;
hidHost
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
hidHost
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
...
...
@@ -1747,7 +1751,7 @@ disconnect(device: string): boolean
断开连接设备的Pan服务。
此接口为系统接口。
**系统接口**
:
此接口为系统接口。
**需要权限**
:ohos.permission.USE_BLUETOOTH
...
...
@@ -1768,7 +1772,7 @@ disconnect(device: string): boolean
**示例:**
```
js
let
panProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
)
;
let
panProfile
=
bluetooth
.
getProfile
Inst
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
)
as
bluetooth
.
PanProfile
;
let
ret
=
panProfile
.
disconnect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
...
...
@@ -1798,7 +1802,7 @@ on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Stat
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
pan state =
'
+
JSON
.
stringify
(
data
));
}
let
panProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
)
;
let
panProfile
=
bluetooth
.
getProfile
Inst
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
)
as
bluetooth
.
PanProfile
;
panProfile
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
...
...
@@ -1828,7 +1832,7 @@ off(type: "connectionStateChange", callback?: Callback<[StateChangeParam](#St
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
pan state =
'
+
JSON
.
stringify
(
data
));
}
let
panProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
)
;
let
panProfile
=
bluetooth
.
getProfile
Inst
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
)
as
bluetooth
.
PanProfile
;
panProfile
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
panProfile
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
...
...
@@ -1840,7 +1844,7 @@ setTethering(enable: boolean): void
设置网络共享状态。
此接口为系统接口。
**系统接口**
:
此接口为系统接口。
**需要权限**
:ohos.permission.DISCOVER_BLUETOOTH
...
...
@@ -1861,7 +1865,7 @@ setTethering(enable: boolean): void
**示例:**
```
js
let
panProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
)
;
let
panProfile
=
bluetooth
.
getProfile
Inst
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
)
as
bluetooth
.
PanProfile
;
let
ret
=
panProfile
.
setTethering
(
true
);
```
...
...
@@ -1872,7 +1876,7 @@ isTetheringOn(): boolean
获取网络共享状态。
此接口为系统接口。
**系统接口**
:
此接口为系统接口。
**系统能力**
:SystemCapability.Communication.Bluetooth.Core。
...
...
@@ -1885,7 +1889,7 @@ isTetheringOn(): boolean
**示例:**
```
js
let
panProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
)
;
let
panProfile
=
bluetooth
.
getProfile
Inst
(
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
)
as
bluetooth
.
PanProfile
;
let
ret
=
panProfile
.
isTetheringOn
();
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录