Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
8dca8f22
D
Docs
项目概览
OpenHarmony
/
Docs
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
8dca8f22
编写于
6月 09, 2022
作者:
S
smartbao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix doc issues
Signed-off-by:
N
smartbao
<
baomin@huawei.com
>
上级
917b71af
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
84 addition
and
24 deletion
+84
-24
zh-cn/application-dev/reference/apis/js-apis-bluetooth.md
zh-cn/application-dev/reference/apis/js-apis-bluetooth.md
+82
-23
zh-cn/application-dev/reference/apis/js-apis-system-bluetooth.md
...pplication-dev/reference/apis/js-apis-system-bluetooth.md
+2
-1
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-bluetooth.md
浏览文件 @
8dca8f22
...
@@ -212,7 +212,7 @@ getProfileConnState(profileId: ProfileId): ProfileConnectionState
...
@@ -212,7 +212,7 @@ getProfileConnState(profileId: ProfileId): ProfileConnectionState
**示例:**
**示例:**
```
js
```
js
let
result
=
bluetooth
.
getProfileConnState
(
PROFILE_A2DP_SOURCE
);
let
result
=
bluetooth
.
getProfileConnState
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
);
```
```
...
@@ -355,7 +355,7 @@ setBluetoothScanMode(mode: ScanMode, duration: number): boolean
...
@@ -355,7 +355,7 @@ setBluetoothScanMode(mode: ScanMode, duration: number): boolean
```
js
```
js
// 设置为可连接可发现才可被远端设备扫描到,可以连接。
// 设置为可连接可发现才可被远端设备扫描到,可以连接。
let
result
=
bluetooth
.
setBluetoothScanMode
(
ScanMode
.
SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE
,
100
);
let
result
=
bluetooth
.
setBluetoothScanMode
(
bluetooth
.
ScanMode
.
SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE
,
100
);
```
```
...
@@ -773,6 +773,14 @@ sppAccept(serverSocket: number, callback: AsyncCallback<number>): void
...
@@ -773,6 +773,14 @@ sppAccept(serverSocket: number, callback: AsyncCallback<number>): void
**示例:**
**示例:**
```
js
```
js
let
serverNumber
=
-
1
;
function
serverSocket
(
code
,
number
)
{
console
.
log
(
'
bluetooth error code:
'
+
code
.
code
);
if
(
code
.
code
==
0
)
{
console
.
log
(
'
bluetooth serverSocket Number:
'
+
number
);
serverNumber
=
number
;
}
}
let
clientNumber
=
-
1
;
let
clientNumber
=
-
1
;
function
acceptClientSocket
(
code
,
number
)
{
function
acceptClientSocket
(
code
,
number
)
{
console
.
log
(
'
bluetooth error code:
'
+
code
.
code
);
console
.
log
(
'
bluetooth error code:
'
+
code
.
code
);
...
@@ -807,6 +815,7 @@ sppConnect(device: string, option: SppOption, callback: AsyncCallback<number&
...
@@ -807,6 +815,7 @@ sppConnect(device: string, option: SppOption, callback: AsyncCallback<number&
**示例:**
**示例:**
```
js
```
js
let
clientNumber
=
-
1
;
let
clientNumber
=
-
1
;
function
clientSocket
(
code
,
number
)
{
function
clientSocket
(
code
,
number
)
{
if
(
code
.
code
!=
0
)
{
if
(
code
.
code
!=
0
)
{
...
@@ -838,6 +847,14 @@ sppCloseServerSocket(socket: number): void
...
@@ -838,6 +847,14 @@ sppCloseServerSocket(socket: number): void
**示例:**
**示例:**
```
js
```
js
let
serverNumber
=
-
1
;
function
serverSocket
(
code
,
number
)
{
console
.
log
(
'
bluetooth error code:
'
+
code
.
code
);
if
(
code
.
code
==
0
)
{
console
.
log
(
'
bluetooth serverSocket Number:
'
+
number
);
serverNumber
=
number
;
}
}
bluetooth
.
sppCloseServerSocket
(
serverNumber
);
bluetooth
.
sppCloseServerSocket
(
serverNumber
);
```
```
...
@@ -860,6 +877,15 @@ sppCloseClientSocket(socket: number): void
...
@@ -860,6 +877,15 @@ sppCloseClientSocket(socket: number): void
**示例:**
**示例:**
```
js
```
js
let
clientNumber
=
-
1
;
function
clientSocket
(
code
,
number
)
{
if
(
code
.
code
!=
0
)
{
return
;
}
console
.
log
(
'
bluetooth serverSocket Number:
'
+
number
);
// 获取的clientNumber用作客户端后续读/写操作socket的id。
clientNumber
=
number
;
}
bluetooth
.
sppCloseClientSocket
(
clientNumber
);
bluetooth
.
sppCloseClientSocket
(
clientNumber
);
```
```
...
@@ -888,6 +914,15 @@ sppWrite(clientSocket: number, data: ArrayBuffer): boolean
...
@@ -888,6 +914,15 @@ sppWrite(clientSocket: number, data: ArrayBuffer): boolean
**示例:**
**示例:**
```
js
```
js
let
clientNumber
=
-
1
;
function
clientSocket
(
code
,
number
)
{
if
(
code
.
code
!=
0
)
{
return
;
}
console
.
log
(
'
bluetooth serverSocket Number:
'
+
number
);
// 获取的clientNumber用作客户端后续读/写操作socket的id。
clientNumber
=
number
;
}
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
data
=
new
Uint8Array
(
arrayBuffer
);
let
data
=
new
Uint8Array
(
arrayBuffer
);
data
[
0
]
=
123
;
data
[
0
]
=
123
;
...
@@ -923,6 +958,15 @@ on(type: "sppRead", clientSocket: number, callback: Callback<ArrayBuffer>)
...
@@ -923,6 +958,15 @@ on(type: "sppRead", clientSocket: number, callback: Callback<ArrayBuffer>)
**示例:**
**示例:**
```
js
```
js
let
clientNumber
=
-
1
;
function
clientSocket
(
code
,
number
)
{
if
(
code
.
code
!=
0
)
{
return
;
}
console
.
log
(
'
bluetooth serverSocket Number:
'
+
number
);
// 获取的clientNumber用作客户端后续读/写操作socket的id。
clientNumber
=
number
;
}
function
dataRead
(
dataBuffer
)
{
function
dataRead
(
dataBuffer
)
{
let
data
=
new
Uint8Array
(
dataBuffer
);
let
data
=
new
Uint8Array
(
dataBuffer
);
console
.
log
(
'
bluetooth data is:
'
+
data
[
0
]);
console
.
log
(
'
bluetooth data is:
'
+
data
[
0
]);
...
@@ -954,6 +998,15 @@ off(type: "sppRead", clientSocket: number, callback?: Callback<ArrayBuffer>
...
@@ -954,6 +998,15 @@ off(type: "sppRead", clientSocket: number, callback?: Callback<ArrayBuffer>
**示例:**
**示例:**
```
js
```
js
let
clientNumber
=
-
1
;
function
clientSocket
(
code
,
number
)
{
if
(
code
.
code
!=
0
)
{
return
;
}
console
.
log
(
'
bluetooth serverSocket Number:
'
+
number
);
// 获取的clientNumber用作客户端后续读/写操作socket的id。
clientNumber
=
number
;
}
bluetooth
.
off
(
'
sppRead
'
,
clientNumber
);
bluetooth
.
off
(
'
sppRead
'
,
clientNumber
);
```
```
...
@@ -981,7 +1034,7 @@ getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfi
...
@@ -981,7 +1034,7 @@ getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfi
**示例:**
**示例:**
```
js
```
js
let
a2dpSrc
=
bluetooth
.
getProfile
(
PROFILE_A2DP_SOURCE
);
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
);
```
```
## bluetooth.getProfile<sup>9+</sup><a name="getProfile"></a>
## bluetooth.getProfile<sup>9+</sup><a name="getProfile"></a>
...
@@ -1007,7 +1060,7 @@ getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfi
...
@@ -1007,7 +1060,7 @@ getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfi
**示例:**
**示例:**
```
js
```
js
let
hidHost
=
bluetooth
.
getProfile
(
PROFILE_HID_HOST
);
let
hidHost
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
);
```
```
...
@@ -1239,7 +1292,7 @@ getConnectionDevices(): Array<string>
...
@@ -1239,7 +1292,7 @@ getConnectionDevices(): Array<string>
**示例:**
**示例:**
```
js
```
js
let
a2dpSrc
=
bluetooth
.
getProfile
(
PROFILE_A2DP_SOURCE
)
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
)
let
retArray
=
a2dpSrc
.
getConnectionDevices
();
let
retArray
=
a2dpSrc
.
getConnectionDevices
();
```
```
...
@@ -1268,7 +1321,7 @@ getDeviceState(device: string): ProfileConnectionState
...
@@ -1268,7 +1321,7 @@ getDeviceState(device: string): ProfileConnectionState
**示例:**
**示例:**
```
js
```
js
let
a2dpSrc
=
bluetooth
.
getProfile
(
PROFILE_A2DP_SOURCE
)
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
)
let
ret
=
a2dpSrc
.
getDeviceState
(
'
XX:XX:XX:XX:XX:XX
'
);
let
ret
=
a2dpSrc
.
getDeviceState
(
'
XX:XX:XX:XX:XX:XX
'
);
```
```
...
@@ -1302,7 +1355,7 @@ connect(device: string): boolean
...
@@ -1302,7 +1355,7 @@ connect(device: string): boolean
**示例:**
**示例:**
```
js
```
js
let
a2dpSrc
=
bluetooth
.
getProfile
(
PROFILE_A2DP_SOURCE
)
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
)
let
ret
=
a2dpSrc
.
connect
(
'
XX:XX:XX:XX:XX:XX
'
);
let
ret
=
a2dpSrc
.
connect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
```
...
@@ -1332,7 +1385,7 @@ disconnect(device: string): boolean
...
@@ -1332,7 +1385,7 @@ disconnect(device: string): boolean
**示例:**
**示例:**
```
js
```
js
let
a2dpSrc
=
bluetooth
.
getProfile
(
PROFILE_A2DP_SOURCE
);
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
);
let
ret
=
a2dpSrc
.
disconnect
(
'
XX:XX:XX:XX:XX:XX
'
);
let
ret
=
a2dpSrc
.
disconnect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
```
...
@@ -1362,7 +1415,7 @@ on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Stat
...
@@ -1362,7 +1415,7 @@ on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Stat
function
onReceiveEvent
(
data
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
a2dp state =
'
+
JSON
.
stringify
(
data
));
console
.
info
(
'
a2dp state =
'
+
JSON
.
stringify
(
data
));
}
}
let
a2dpSrc
=
bluetooth
.
getProfile
(
PROFILE_A2DP_SOURCE
);
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
);
a2dpSrc
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
a2dpSrc
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
```
...
@@ -1392,7 +1445,7 @@ off(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Sta
...
@@ -1392,7 +1445,7 @@ off(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Sta
function
onReceiveEvent
(
data
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
a2dp state =
'
+
JSON
.
stringify
(
data
));
console
.
info
(
'
a2dp state =
'
+
JSON
.
stringify
(
data
));
}
}
let
a2dpSrc
=
bluetooth
.
getProfile
(
PROFILE_A2DP_SOURCE
);
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
);
a2dpSrc
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
a2dpSrc
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
a2dpSrc
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
a2dpSrc
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
```
...
@@ -1421,7 +1474,7 @@ getPlayingState(device: string): PlayingState
...
@@ -1421,7 +1474,7 @@ getPlayingState(device: string): PlayingState
**示例:**
**示例:**
```
js
```
js
let
a2dpSrc
=
bluetooth
.
getProfile
(
PROFILE_A2DP_SOURCE
);
let
a2dpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
);
let
state
=
a2dpSrc
.
getPlayingState
(
'
XX:XX:XX:XX:XX:XX
'
);
let
state
=
a2dpSrc
.
getPlayingState
(
'
XX:XX:XX:XX:XX:XX
'
);
```
```
...
@@ -1456,7 +1509,7 @@ connect(device: string): boolean
...
@@ -1456,7 +1509,7 @@ connect(device: string): boolean
**示例:**
**示例:**
```
js
```
js
let
hfpAg
=
bluetooth
.
getProfile
(
PROFILE_HANDS_FREE_AUDIO_GATEWAY
);
let
hfpAg
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HANDS_FREE_AUDIO_GATEWAY
);
let
ret
=
hfpAg
.
connect
(
'
XX:XX:XX:XX:XX:XX
'
);
let
ret
=
hfpAg
.
connect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
```
...
@@ -1486,7 +1539,7 @@ disconnect(device: string): boolean
...
@@ -1486,7 +1539,7 @@ disconnect(device: string): boolean
**示例:**
**示例:**
```
js
```
js
let
hfpAg
=
bluetooth
.
getProfile
(
PROFILE_HANDS_FREE_AUDIO_GATEWAY
);
let
hfpAg
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HANDS_FREE_AUDIO_GATEWAY
);
let
ret
=
hfpAg
.
disconnect
(
'
XX:XX:XX:XX:XX:XX
'
);
let
ret
=
hfpAg
.
disconnect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
```
...
@@ -1516,7 +1569,7 @@ on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Stat
...
@@ -1516,7 +1569,7 @@ on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Stat
function
onReceiveEvent
(
data
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
hfp state =
'
+
JSON
.
stringify
(
data
));
console
.
info
(
'
hfp state =
'
+
JSON
.
stringify
(
data
));
}
}
let
hfpAg
=
bluetooth
.
getProfile
(
PROFILE_HANDS_FREE_AUDIO_GATEWAY
);
let
hfpAg
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HANDS_FREE_AUDIO_GATEWAY
);
hfpAg
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
hfpAg
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
```
...
@@ -1546,7 +1599,7 @@ off(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Sta
...
@@ -1546,7 +1599,7 @@ off(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Sta
function
onReceiveEvent
(
data
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
hfp state =
'
+
JSON
.
stringify
(
data
));
console
.
info
(
'
hfp state =
'
+
JSON
.
stringify
(
data
));
}
}
let
hfpAg
=
bluetooth
.
getProfile
(
PROFILE_HANDS_FREE_AUDIO_GATEWAY
);
let
hfpAg
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HANDS_FREE_AUDIO_GATEWAY
);
hfpAg
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
hfpAg
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
hfpAg
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
hfpAg
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
```
...
@@ -1584,7 +1637,7 @@ connect(device: string): boolean
...
@@ -1584,7 +1637,7 @@ connect(device: string): boolean
**示例:**
**示例:**
```
js
```
js
let
hidHostProfile
=
bluetooth
.
getProfile
(
PROFILE_HID_HOST
);
let
hidHostProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
);
let
ret
=
hidHostProfile
.
connect
(
'
XX:XX:XX:XX:XX:XX
'
);
let
ret
=
hidHostProfile
.
connect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
```
...
@@ -1616,7 +1669,7 @@ disconnect(device: string): boolean
...
@@ -1616,7 +1669,7 @@ disconnect(device: string): boolean
**示例:**
**示例:**
```
js
```
js
let
hidHostProfile
=
bluetooth
.
getProfile
(
PROFILE_HID_HOST
);
let
hidHostProfile
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
);
let
ret
=
hidHostProfile
.
disconnect
(
'
XX:XX:XX:XX:XX:XX
'
);
let
ret
=
hidHostProfile
.
disconnect
(
'
XX:XX:XX:XX:XX:XX
'
);
```
```
...
@@ -1646,7 +1699,7 @@ on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Stat
...
@@ -1646,7 +1699,7 @@ on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Stat
function
onReceiveEvent
(
data
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
hidHost state =
'
+
JSON
.
stringify
(
data
));
console
.
info
(
'
hidHost state =
'
+
JSON
.
stringify
(
data
));
}
}
let
hidHost
=
bluetooth
.
getProfile
(
PROFILE_HID_HOST
);
let
hidHost
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
);
hidHost
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
hidHost
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
```
...
@@ -1676,7 +1729,7 @@ off(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Sta
...
@@ -1676,7 +1729,7 @@ off(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Sta
function
onReceiveEvent
(
data
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
hidHost state =
'
+
JSON
.
stringify
(
data
));
console
.
info
(
'
hidHost state =
'
+
JSON
.
stringify
(
data
));
}
}
let
hidHost
=
bluetooth
.
getProfile
(
PROFILE_HID_HOST
);
let
hidHost
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
);
hidHost
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
hidHost
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
hidHost
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
hidHost
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
```
```
...
@@ -1819,7 +1872,7 @@ cccV[0] = 1;
...
@@ -1819,7 +1872,7 @@ cccV[0] = 1;
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferC
,
descriptors
:
descriptors
};
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferC
,
descriptors
:
descriptors
};
let
characteristicN
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
let
characteristicN
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001821-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferC
,
descriptors
:
descriptors
N
};
characteristicUuid
:
'
00001821-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferC
,
descriptors
:
descriptors
};
characteristics
[
0
]
=
characteristic
;
characteristics
[
0
]
=
characteristic
;
// 创建gattService
// 创建gattService
...
@@ -1911,8 +1964,11 @@ server端特征值发生变化时,主动通知已连接的client设备。
...
@@ -1911,8 +1964,11 @@ server端特征值发生变化时,主动通知已连接的client设备。
**示例:**
**示例:**
```
js
```
js
let
arrayBufferC
=
new
ArrayBuffer
(
8
);
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferC
,
descriptors
:
descriptors
};
let
notifyCharacteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
let
notifyCharacteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001821-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
notifyCc
c
.
characteristicValue
,
confirm
:
false
};
characteristicUuid
:
'
00001821-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
characteristi
c
.
characteristicValue
,
confirm
:
false
};
let
server
=
bluetooth
.
BLE
.
createGattServer
();
let
server
=
bluetooth
.
BLE
.
createGattServer
();
server
.
notifyCharacteristicChanged
(
'
XX:XX:XX:XX:XX:XX
'
,
notifyCharacteristic
);
server
.
notifyCharacteristicChanged
(
'
XX:XX:XX:XX:XX:XX
'
,
notifyCharacteristic
);
```
```
...
@@ -2488,7 +2544,7 @@ client端获取蓝牙低功耗设备的所有服务,即服务发现。
...
@@ -2488,7 +2544,7 @@ client端获取蓝牙低功耗设备的所有服务,即服务发现。
// Promise 模式
// Promise 模式
let
device
=
bluetooth
.
BLE
.
createGattClientDevice
(
'
XX:XX:XX:XX:XX:XX
'
);
let
device
=
bluetooth
.
BLE
.
createGattClientDevice
(
'
XX:XX:XX:XX:XX:XX
'
);
device
.
connect
();
device
.
connect
();
let
services
=
device
.
getServices
();
var
services
=
device
.
getServices
();
console
.
log
(
"
bluetooth services size is
"
,
services
.
length
);
console
.
log
(
"
bluetooth services size is
"
,
services
.
length
);
for
(
let
i
=
0
;
i
<
services
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
services
.
length
;
i
++
)
{
...
@@ -2826,8 +2882,11 @@ setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolea
...
@@ -2826,8 +2882,11 @@ setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolea
**示例:**
**示例:**
```
js
```
js
let
arrayBufferC
=
new
ArrayBuffer
(
8
);
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferC
,
descriptors
:
descriptors
};
let
device
=
bluetooth
.
BLE
.
createGattClientDevice
(
'
XX:XX:XX:XX:XX:XX
'
);
let
device
=
bluetooth
.
BLE
.
createGattClientDevice
(
'
XX:XX:XX:XX:XX:XX
'
);
device
.
setNotifyCharacteristicChanged
(
notifyCc
c
,
false
);
device
.
setNotifyCharacteristicChanged
(
characteristi
c
,
false
);
```
```
...
...
zh-cn/application-dev/reference/apis/js-apis-system-bluetooth.md
浏览文件 @
8dca8f22
...
@@ -71,6 +71,7 @@ import bluetooth from '@system.bluetooth';
...
@@ -71,6 +71,7 @@ import bluetooth from '@system.bluetooth';
```
```
bluetooth.stopBLEScan({
bluetooth.stopBLEScan({
interval:0,
success() {
success() {
console.log('call bluetooth.stopBLEScan success.');
console.log('call bluetooth.stopBLEScan success.');
},
},
...
@@ -119,7 +120,7 @@ import bluetooth from '@system.bluetooth';
...
@@ -119,7 +120,7 @@ import bluetooth from '@system.bluetooth';
**示例:**
**示例:**
```
```
bluetooth.start
a
BLEScan({
bluetooth.startBLEScan({
success() {
success() {
bluetooth.subscribeBLEFound({
bluetooth.subscribeBLEFound({
success(data) {
success(data) {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录