未验证 提交 922a9079 编写于 作者: O openharmony_ci 提交者: Gitee

!18430 bluetooth 示例代码修改,合入3.2release

Merge pull request !18430 from lverpeng/OpenHarmony-3.2-Release
...@@ -893,7 +893,7 @@ try { ...@@ -893,7 +893,7 @@ try {
on(type: "stateChange", callback: Callback<BluetoothState>): void on(type: "stateChange", callback: Callback<BluetoothState>): void
订阅蓝牙连接状态改变事件。 订阅蓝牙设备开关状态事件。
**需要权限**:ohos.permission.USE_BLUETOOTH **需要权限**:ohos.permission.USE_BLUETOOTH
...@@ -932,7 +932,7 @@ try { ...@@ -932,7 +932,7 @@ try {
off(type: "stateChange", callback?: Callback<BluetoothState>): void off(type: "stateChange", callback?: Callback<BluetoothState>): void
取消订阅蓝牙连接状态改变事件。 取消订阅蓝牙设备开关状态事件。
**需要权限**:ohos.permission.USE_BLUETOOTH **需要权限**:ohos.permission.USE_BLUETOOTH
...@@ -2075,7 +2075,7 @@ connect(device: string): void ...@@ -2075,7 +2075,7 @@ connect(device: string): void
```js ```js
try { try {
let hidHostProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile; let hidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
hidHostProfile.connect('XX:XX:XX:XX:XX:XX'); hidHostProfile.connect('XX:XX:XX:XX:XX:XX');
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
...@@ -2116,7 +2116,7 @@ disconnect(device: string): void ...@@ -2116,7 +2116,7 @@ disconnect(device: string): void
```js ```js
try { try {
let hidHostProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile; let hidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX'); hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX');
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
...@@ -2145,7 +2145,7 @@ on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Stat ...@@ -2145,7 +2145,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 = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile; let hidHost = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
hidHost.on('connectionStateChange', onReceiveEvent); hidHost.on('connectionStateChange', onReceiveEvent);
``` ```
...@@ -2171,7 +2171,7 @@ off(type: "connectionStateChange", callback?: Callback<[StateChangeParam](#St ...@@ -2171,7 +2171,7 @@ off(type: "connectionStateChange", callback?: Callback<[StateChangeParam](#St
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('hidHost state = '+ JSON.stringify(data)); console.info('hidHost state = '+ JSON.stringify(data));
} }
let hidHost = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile; let hidHost = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
hidHost.on('connectionStateChange', onReceiveEvent); hidHost.on('connectionStateChange', onReceiveEvent);
hidHost.off('connectionStateChange', onReceiveEvent); hidHost.off('connectionStateChange', onReceiveEvent);
``` ```
...@@ -2215,7 +2215,7 @@ disconnect(device: string): void ...@@ -2215,7 +2215,7 @@ disconnect(device: string): void
```js ```js
try { try {
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile; let panProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
panProfile.disconnect('XX:XX:XX:XX:XX:XX'); panProfile.disconnect('XX:XX:XX:XX:XX:XX');
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
...@@ -2244,7 +2244,7 @@ on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Stat ...@@ -2244,7 +2244,7 @@ on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#Stat
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('pan state = '+ JSON.stringify(data)); console.info('pan state = '+ JSON.stringify(data));
} }
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile; let panProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
panProfile.on('connectionStateChange', onReceiveEvent); panProfile.on('connectionStateChange', onReceiveEvent);
``` ```
...@@ -2270,7 +2270,7 @@ off(type: "connectionStateChange", callback?: Callback<[StateChangeParam](#St ...@@ -2270,7 +2270,7 @@ off(type: "connectionStateChange", callback?: Callback<[StateChangeParam](#St
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('pan state = '+ JSON.stringify(data)); console.info('pan state = '+ JSON.stringify(data));
} }
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile; let panProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
panProfile.on('connectionStateChange', onReceiveEvent); panProfile.on('connectionStateChange', onReceiveEvent);
panProfile.off('connectionStateChange', onReceiveEvent); panProfile.off('connectionStateChange', onReceiveEvent);
``` ```
...@@ -2309,7 +2309,7 @@ setTethering(enable: boolean): void ...@@ -2309,7 +2309,7 @@ setTethering(enable: boolean): void
```js ```js
try { try {
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile; let panProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
panProfile.setTethering(true); panProfile.setTethering(true);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
...@@ -2337,7 +2337,7 @@ isTetheringOn(): boolean ...@@ -2337,7 +2337,7 @@ isTetheringOn(): boolean
```js ```js
try { try {
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile; let panProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
let ret = panProfile.isTetheringOn(); let ret = panProfile.isTetheringOn();
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册