Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
75aaa5ed
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看板
未验证
提交
75aaa5ed
编写于
9月 04, 2023
作者:
O
openharmony_ci
提交者:
Gitee
9月 04, 2023
浏览文件
操作
浏览文件
下载
差异文件
!23727 【分布式DM--monthly_20230815】鸿蒙指南文档ArkTS适配
Merge pull request !23727 from qinlong/monthly_20230815
上级
78e5ac30
0b720145
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
767 addition
and
284 deletion
+767
-284
zh-cn/application-dev/reference/apis/js-apis-device-manager.md
.../application-dev/reference/apis/js-apis-device-manager.md
+516
-191
zh-cn/application-dev/reference/apis/js-apis-distributedDeviceManager.md
...on-dev/reference/apis/js-apis-distributedDeviceManager.md
+251
-93
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-device-manager.md
浏览文件 @
75aaa5ed
# @ohos.distributedHardware.deviceManager (设备管理)
本模块能力已更新至新模块。建议使用新模块的接口进行开发,参见
[
@ohos.distributedDeviceManager
](
js-apis-distributedDeviceManager.md
)
。
本模块提供分布式设备管理能力。
系统应用可调用接口实现如下功能:
...
...
@@ -19,7 +21,7 @@
## 导入模块
```
j
s
```
t
s
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
```
...
...
@@ -41,18 +43,23 @@ createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
let
dmInstance
:
deviceManager
.
Devicemanager
|
null
=
null
;
try
{
deviceManager
.
createDeviceManager
(
"
ohos.samples.jshelloworld
"
,
(
err
,
data
)
=>
{
deviceManager
.
createDeviceManager
(
"
ohos.samples.jshelloworld
"
,
(
err
:
BusinessError
,
data
:
deviceManager
.
Devicemanager
)
=>
{
if
(
err
)
{
console
.
error
(
"
createDeviceManager errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
return
;
}
console
.
info
(
"
createDeviceManager success
"
);
let
dmInstance
=
data
;
dmInstance
=
data
;
});
}
catch
(
err
)
{
console
.
error
(
"
createDeviceManager errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
createDeviceManager errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -241,11 +248,14 @@ release(): void
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
dmInstance
.
release
();
}
catch
(
err
)
{
console
.
error
(
"
release errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
release errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -275,11 +285,15 @@ getTrustedDeviceListSync(): Array<DeviceInfo>
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
var
deviceInfoList
=
dmInstance
.
getTrustedDeviceListSync
();
let
deviceInfoList
:
Array
<
deviceManager
.
DeviceInfo
>
=
dmInstance
.
getTrustedDeviceListSync
();
}
catch
(
err
)
{
console
.
error
(
"
getTrustedDeviceListSync errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getTrustedDeviceListSync errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -315,11 +329,15 @@ getTrustedDeviceListSync(isRefresh: boolean): Array<DeviceInfo>
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
var
deviceInfoList
=
dmInstance
.
getTrustedDeviceListSync
(
true
);
let
deviceInfoList
:
Array
<
deviceManager
.
DeviceInfo
>
=
dmInstance
.
getTrustedDeviceListSync
(
true
);
}
catch
(
err
)
{
console
.
error
(
"
getTrustedDeviceListSync errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getTrustedDeviceListSync errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -341,9 +359,11 @@ getTrustedDeviceList(callback:AsyncCallback<Array<DeviceInfo>>): voi
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
dmInstance
.
getTrustedDeviceList
((
err
,
data
)
=>
{
dmInstance
.
getTrustedDeviceList
((
err
:
BusinessError
,
data
:
deviceManager
.
DeviceInfo
)
=>
{
if
(
err
)
{
console
.
error
(
"
getTrustedDeviceList errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
return
;
...
...
@@ -351,7 +371,8 @@ getTrustedDeviceList(callback:AsyncCallback<Array<DeviceInfo>>): voi
console
.
log
(
'
get trusted device info:
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
getTrustedDeviceList errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getTrustedDeviceList errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -373,10 +394,13 @@ getTrustedDeviceList(): Promise<Array<DeviceInfo>>
**示例:**
```
js
dmInstance
.
getTrustedDeviceList
().
then
((
data
)
=>
{
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
dmInstance
.
getTrustedDeviceList
().
then
((
data
:
Array
<
deviceManager
.
DeviceInfo
>
)
=>
{
console
.
log
(
'
get trusted device info:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
"
getTrustedDeviceList errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
});
```
...
...
@@ -407,11 +431,15 @@ getLocalDeviceInfoSync(): [DeviceInfo](#deviceinfo)
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
var
d
eviceInfo
=
dmInstance
.
getLocalDeviceInfoSync
();
let
deviceInfo
:
deviceManager
.
D
eviceInfo
=
dmInstance
.
getLocalDeviceInfoSync
();
}
catch
(
err
)
{
console
.
error
(
"
getLocalDeviceInfoSync errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getLocalDeviceInfoSync errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -433,9 +461,13 @@ getLocalDeviceInfo(callback:AsyncCallback<DeviceInfo>): void
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
dmInstance
.
getLocalDeviceInfo
((
err
,
data
)
=>
{
dmInstance
.
getLocalDeviceInfo
((
err
:
BusinessError
,
data
:
deviceManager
.
DeviceInfo
)
=>
{
if
(
err
)
{
console
.
error
(
"
getLocalDeviceInfo errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
return
;
...
...
@@ -443,7 +475,8 @@ getLocalDeviceInfo(callback:AsyncCallback<DeviceInfo>): void
console
.
log
(
'
get local device info:
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
getLocalDeviceInfo errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getLocalDeviceInfo errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -465,10 +498,13 @@ getLocalDeviceInfo(): Promise<DeviceInfo>
**示例:**
```
js
dmInstance
.
getLocalDeviceInfo
().
then
((
data
)
=>
{
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
dmInstance
.
getLocalDeviceInfo
().
then
((
data
:
deviceManager
.
DeviceInfo
)
=>
{
console
.
log
(
'
get local device info:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
"
getLocalDeviceInfo errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
});
```
...
...
@@ -492,11 +528,14 @@ getDeviceInfo(networkId: string, callback:AsyncCallback<DeviceInfo>): void
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
// 设备网络标识,可以从可信设备列表中获取
let
networkId
=
"
xxxxxxx
"
dmInstance
.
getDeviceInfo
(
networkId
,
(
err
,
data
)
=>
{
dmInstance
.
getDeviceInfo
(
networkId
,
(
err
:
BusinessError
,
data
:
deviceManager
.
DeviceInfo
)
=>
{
if
(
err
)
{
console
.
error
(
"
getDeviceInfo errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
return
;
...
...
@@ -504,7 +543,8 @@ getDeviceInfo(networkId: string, callback:AsyncCallback<DeviceInfo>): void
console
.
log
(
'
get device info:
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
getDeviceInfo errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getDeviceInfo errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -532,12 +572,15 @@ getDeviceInfo(networkId: string): Promise<DeviceInfo>
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
// 设备网络标识,可以从可信设备列表中获取
let
networkId
=
"
xxxxxxx
"
dmInstance
.
getDeviceInfo
(
networkId
).
then
((
data
)
=>
{
dmInstance
.
getDeviceInfo
(
networkId
).
then
((
data
:
deviceManager
.
DeviceInfo
)
=>
{
console
.
log
(
'
get device info:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
"
getDeviceInfo errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
});
```
...
...
@@ -569,22 +612,35 @@ startDeviceDiscovery(subscribeInfo: SubscribeInfo): void
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
interface
SubscribeInfo
{
subscribeId
:
number
,
mode
:
number
,
// 主动模式
medium
:
number
,
// 自动发现类型,同时支持多种发现类型
freq
:
number
,
// 高频率
isSameAccount
:
boolean
,
isWakeRemote
:
boolean
,
capability
:
number
};
// 生成发现标识,随机数确保每次调用发现接口的标识不一致
var
subscribeId
=
Math
.
floor
(
Math
.
random
()
*
10000
+
1000
);
var
s
ubscribeInfo
=
{
"
subscribeId
"
:
subscribeId
,
"
mode
"
:
0xAA
,
// 主动模式
"
medium
"
:
0
,
// 自动发现类型,同时支持多种发现类型
"
freq
"
:
2
,
// 高频率
"
isSameAccount
"
:
false
,
"
isWakeRemote
"
:
false
,
"
capability
"
:
1
let
subscribeId
=
Math
.
floor
(
Math
.
random
()
*
10000
+
1000
);
let
subscribeInfo
:
S
ubscribeInfo
=
{
subscribeId
:
subscribeId
,
mode
:
0xAA
,
// 主动模式
medium
:
0
,
// 自动发现类型,同时支持多种发现类型
freq
:
2
,
// 高频率
isSameAccount
:
false
,
isWakeRemote
:
false
,
capability
:
1
};
try
{
dmInstance
.
startDeviceDiscovery
(
subscribeInfo
);
// 当有设备发现时,通过deviceFound回调通知给应用程序
}
catch
(
err
)
{
console
.
error
(
"
startDeviceDiscovery errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
startDeviceDiscovery errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -616,31 +672,57 @@ startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
interface
Filters
{
type
:
string
,
value
:
number
}
interface
FilterOptions
{
filter_op
:
string
,
// 可选, 默认"OR"
filters
:
Filters
[]
}
interface
SubscribeInfo
{
subscribeId
:
number
,
mode
:
number
,
// 主动模式
medium
:
number
,
// 自动发现类型,同时支持多种发现类型
freq
:
number
,
// 高频率
isSameAccount
:
boolean
,
isWakeRemote
:
boolean
,
capability
:
number
}
// 生成发现标识,随机数确保每次调用发现接口的标识不一致
var
subscribeId
=
Math
.
floor
(
Math
.
random
()
*
10000
+
1000
);
var
s
ubscribeInfo
=
{
"
subscribeId
"
:
subscribeId
,
"
mode
"
:
0xAA
,
// 主动模式
"
medium
"
:
0
,
// 自动发现类型,同时支持多种发现类型
"
freq
"
:
2
,
// 高频率
"
isSameAccount
"
:
false
,
"
isWakeRemote
"
:
false
,
"
capability
"
:
1
let
subscribeId
=
Math
.
floor
(
Math
.
random
()
*
10000
+
1000
);
let
subscribeInfo
:
S
ubscribeInfo
=
{
subscribeId
:
subscribeId
,
mode
:
0xAA
,
// 主动模式
medium
:
0
,
// 自动发现类型,同时支持多种发现类型
freq
:
2
,
// 高频率
isSameAccount
:
false
,
isWakeRemote
:
false
,
capability
:
1
};
var
filterOptions
=
{
"
filter_op
"
:
"
OR
"
,
// 可选, 默认"OR"
"
filters
"
:
[
{
"
type
"
:
"
range
"
,
"
value
"
:
50
// 需过滤发现设备的距离,单位(cm)
}
]
let
filters
:
Filters
[]
=
[
{
type
:
"
range
"
,
value
:
50
// 需过滤发现设备的距离,单位(cm)
}
]
let
filterOptions
:
FilterOptions
=
{
filter_op
:
"
OR
"
,
// 可选, 默认"OR"
filters
:
filters
};
try
{
dmInstance
.
startDeviceDiscovery
(
subscribeInfo
,
JSON
.
stringify
(
filterOptions
));
// 当有设备发现时,通过deviceFound回调通知给应用程序
}
catch
(
err
)
{
console
.
error
(
"
startDeviceDiscovery errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
startDeviceDiscovery errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -670,13 +752,16 @@ stopDeviceDiscovery(subscribeId: number): void
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
// stopDeviceDiscovery和startDeviceDiscovery需配对使用,入参需要和startDeviceDiscovery接口传入的subscribeId值相等
var
subscribeId
=
12345
;
let
subscribeId
=
12345
;
dmInstance
.
stopDeviceDiscovery
(
subscribeId
);
}
catch
(
err
)
{
console
.
error
(
"
stopDeviceDiscovery errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
stopDeviceDiscovery errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -707,19 +792,30 @@ publishDeviceDiscovery(publishInfo: PublishInfo): void
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
interface
PublishInfo
{
publishId
:
number
,
mode
:
number
,
// 主动模式
freq
:
number
,
// 高频率
ranging
:
boolean
// 支持发现时测距
};
// 生成发布标识,随机数确保每次调用发布接口的标识不一致
var
publishId
=
Math
.
floor
(
Math
.
random
()
*
10000
+
1000
);
var
p
ublishInfo
=
{
"
publishId
"
:
publishId
,
"
mode
"
:
0xAA
,
// 主动模式
"
freq
"
:
2
,
// 高频率
"
ranging
"
:
true
// 支持发现时测距
let
publishId
=
Math
.
floor
(
Math
.
random
()
*
10000
+
1000
);
let
publishInfo
:
P
ublishInfo
=
{
publishId
:
publishId
,
mode
:
0xAA
,
// 主动模式
freq
:
2
,
// 高频率
ranging
:
true
// 支持发现时测距
};
try
{
dmInstance
.
publishDeviceDiscovery
(
publishInfo
);
// 当有发布结果时,通过回调通知给应用程序
}
catch
(
err
)
{
console
.
error
(
"
publishDeviceDiscovery errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
publishDeviceDiscovery errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -749,13 +845,16 @@ unPublishDeviceDiscovery(publishId: number): void
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
// unPublishDeviceDiscovery和publishDeviceDiscovery配对使用,入参需要和publishDeviceDiscovery接口传入的publishId值相等
var
publishId
=
12345
;
let
publishId
=
12345
;
dmInstance
.
unPublishDeviceDiscovery
(
publishId
);
}
catch
(
err
)
{
console
.
error
(
"
unPublishDeviceDiscovery errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
unPublishDeviceDiscovery errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -779,27 +878,55 @@ authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: Async
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
deviceId
:
string
=
""
pinToken
?:
number
=
0
}
interface
DeviceInfo
{
deviceId
:
string
,
deviceName
:
string
deviceType
:
number
,
networkId
:
string
,
range
:
number
};
interface
ExtraInfo
{
targetPkgName
:
string
,
appName
:
string
,
appDescription
:
string
,
business
:
string
}
interface
AuthParam
{
authType
:
number
,
// 认证类型: 1 - 无帐号PIN码认证
extraInfo
:
ExtraInfo
}
// 认证的设备信息,可以从发现的结果中获取
var
deviceInfo
=
{
"
deviceId
"
:
"
XXXXXXXX
"
,
"
deviceName
"
:
""
,
"
deviceType
"
:
0x0E
,
"
networkId
"
:
"
xxxxxxx
"
,
"
range
"
:
0
let
deviceInfo
:
DeviceInfo
=
{
deviceId
:
"
XXXXXXXX
"
,
deviceName
:
""
,
deviceType
:
0x0E
,
networkId
:
"
xxxxxxx
"
,
range
:
0
};
let
extraInfo
=
{
'
targetPkgName
'
:
'
ohos.samples.xxx
'
,
'
appName
'
:
'
xxx
'
,
'
appDescription
'
:
'
xxx
'
,
'
business
'
:
'
0
'
let
extraInfo
:
ExtraInfo
=
{
targetPkgName
:
'
ohos.samples.xxx
'
,
appName
:
'
xxx
'
,
appDescription
:
'
xxx
'
,
business
:
'
0
'
}
let
authParam
=
{
'
authType
'
:
1
,
// 认证类型: 1 - 无帐号PIN码认证
'
extraInfo
'
:
extraInfo
let
authParam
:
AuthParam
=
{
authType
:
1
,
// 认证类型: 1 - 无帐号PIN码认证
extraInfo
:
extraInfo
}
try
{
dmInstance
.
authenticateDevice
(
deviceInfo
,
authParam
,
(
err
,
d
ata
)
=>
{
dmInstance
.
authenticateDevice
(
deviceInfo
,
authParam
,
(
err
:
BusinessError
,
data
:
D
ata
)
=>
{
if
(
err
)
{
console
.
error
(
"
authenticateDevice errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
return
;
...
...
@@ -808,7 +935,8 @@ authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: Async
let
token
=
data
.
pinToken
;
});
}
catch
(
err
)
{
console
.
error
(
"
authenticateDevice errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
authenticateDevice errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -838,18 +966,29 @@ unAuthenticateDevice(deviceInfo: DeviceInfo): void
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
interface
DeviceInfo
{
deviceId
:
string
,
deviceName
:
string
,
deviceType
:
number
,
networkId
:
string
,
range
:
number
}
try
{
var
deviceInfo
=
{
"
deviceId
"
:
"
XXXXXXXX
"
,
"
deviceName
"
:
""
,
"
deviceType
"
:
0x0E
,
"
networkId
"
:
"
xxxxxxx
"
,
"
range
"
:
0
let
deviceInfo
:
DeviceInfo
=
{
deviceId
:
"
XXXXXXXX
"
,
deviceName
:
""
,
deviceType
:
0x0E
,
networkId
:
"
xxxxxxx
"
,
range
:
0
};
dmInstance
.
unAuthenticateDevice
(
deviceInfo
);
}
catch
(
err
)
{
console
.
error
(
"
unAuthenticateDevice errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
unAuthenticateDevice errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -872,22 +1011,46 @@ verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback<{deviceId: string,
**示例:**
```
js
let
authInfo
=
{
"
authType
"
:
1
,
"
token
"
:
123456
,
"
extraInfo
"
:
{}
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
interface
ExtraInfo
{
authType
:
number
,
token
:
number
}
interface
AuthInfo
{
authType
:
number
,
token
:
number
,
extraInfo
:
ExtraInfo
}
class
Data
{
deviceId
:
string
=
""
level
:
number
=
0
}
let
extraInfo
:
ExtraInfo
=
{
authType
:
0
,
token
:
0
}
let
authInfo
:
AuthInfo
=
{
authType
:
1
,
token
:
123456
,
extraInfo
:
extraInfo
}
try
{
dmInstance
.
verifyAuthInfo
(
authInfo
,
(
err
,
d
ata
)
=>
{
if
(
err
)
{
console
.
error
(
"
verifyAuthInfo errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
return
;
dmInstance
.
verifyAuthInfo
(
authInfo
,
(
err
:
BusinessError
,
data
:
D
ata
)
=>
{
if
(
err
)
{
console
.
error
(
"
verifyAuthInfo errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
return
;
}
console
.
info
(
"
verifyAuthInfo result:
"
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
verifyAuthInfo errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
verifyAuthInfo errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -910,7 +1073,9 @@ setUserOperation(operateAction: number, params: string): void;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
/*
operateAction = 0 - 允许授权
...
...
@@ -923,7 +1088,8 @@ setUserOperation(operateAction: number, params: string): void;
let
operation
=
0
;
dmInstance
.
setUserOperation
(
operation
,
"
extra
"
)
}
catch
(
err
)
{
console
.
error
(
"
setUserOperation errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
setUserOperation errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -946,13 +1112,25 @@ requestCredentialRegisterInfo(requestInfo: string, callback: AsyncCallback<{regi
**示例:**
```
js
let
credentialInfo
=
{
"
version
"
:
"
1.2.3
"
,
"
userId
"
:
"
123
"
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
interface
CredentialInfo
{
version
:
string
,
userId
:
string
}
class
Data
{
registerInfo
:
string
=
""
}
let
credentialInfo
:
CredentialInfo
=
{
version
:
"
1.2.3
"
,
userId
:
"
123
"
}
try
{
dmInstance
.
requestCredentialRegisterInfo
(
credentialInfo
,
(
data
)
=>
{
dmInstance
.
requestCredentialRegisterInfo
(
credentialInfo
,
(
data
:
Data
)
=>
{
if
(
data
)
{
console
.
info
(
"
requestCredentialRegisterInfo result:
"
+
JSON
.
stringify
(
data
));
}
else
{
...
...
@@ -960,7 +1138,8 @@ requestCredentialRegisterInfo(requestInfo: string, callback: AsyncCallback<{regi
}
});
}
catch
(
err
)
{
console
.
error
(
"
requestCredentialRegisterInfo err:
"
+
err
.
code
+
"
,
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
requestCredentialRegisterInfo err:
"
+
e
.
code
+
"
,
"
+
e
.
message
);
}
```
...
...
@@ -983,29 +1162,57 @@ importCredential(credentialInfo: string, callback: AsyncCallback<{resultInfo: st
**示例:**
```
js
let
credentialInfo
=
{
"
processType
"
:
1
,
"
authType
"
:
1
,
"
userId
"
:
"
123
"
,
"
deviceId
"
:
"
aaa
"
,
"
version
"
:
"
1.2.3
"
,
"
devicePk
"
:
"
0000
"
,
"
credentialData
"
:
[
{
"
credentialType
"
:
2
,
"
credentialId
"
:
"
102
"
,
"
serverPk
"
:
"
3059301306072A8648CE3D020106082A8648CE3D03
"
,
"
pkInfoSignature
"
:
"
30440220490BCB4F822004C9A76AB8D97F80041FC0E
"
,
"
pkInfo
"
:
""
,
"
authCode
"
:
""
,
"
peerDeviceId
"
:
""
}
]
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
resultInfo
:
string
=
""
}
interface
CredentialData
{
credentialType
:
number
,
credentialId
:
string
,
serverPk
:
string
,
pkInfoSignature
:
string
,
pkInfo
:
string
,
authCode
:
string
,
peerDeviceId
:
string
}
interface
CredentialInfo
{
processType
:
number
,
authType
:
number
,
userId
:
string
,
deviceId
:
string
,
version
:
string
,
devicePk
:
string
,
credentialData
:
CredentialData
[]
}
let
credentialData
:
CredentialData
=
[
{
credentialType
:
2
,
credentialId
:
"
102
"
,
serverPk
:
"
3059301306072A8648CE3D020106082A8648CE3D03
"
,
pkInfoSignature
:
"
30440220490BCB4F822004C9A76AB8D97F80041FC0E
"
,
pkInfo
:
""
,
authCode
:
""
,
peerDeviceId
:
""
}
]
let
credentialInfo
:
CredentialInfo
=
{
processType
:
1
,
authType
:
1
,
userId
:
"
123
"
,
deviceId
:
"
aaa
"
,
version
:
"
1.2.3
"
,
devicePk
:
"
0000
"
,
credentialData
:
credentialData
}
try
{
dmInstance
.
importCredential
(
credentialInfo
,
(
data
)
=>
{
dmInstance
.
importCredential
(
credentialInfo
,
(
data
:
Data
)
=>
{
if
(
data
)
{
console
.
info
(
"
importCredential result:
"
+
JSON
.
stringify
(
data
));
}
else
{
...
...
@@ -1013,7 +1220,8 @@ importCredential(credentialInfo: string, callback: AsyncCallback<{resultInfo: st
}
});
}
catch
(
err
)
{
console
.
error
(
"
importCredential err:
"
+
err
.
code
+
"
,
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
importCredential err:
"
+
e
.
code
+
"
,
"
+
e
.
message
);
}
```
...
...
@@ -1036,14 +1244,27 @@ deleteCredential(queryInfo: string, callback: AsyncCallback<{resultInfo: string}
**示例:**
```
js
let
queryInfo
=
{
"
processType
"
:
1
,
"
authType
"
:
1
,
"
userId
"
:
"
123
"
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
resultInfo
:
string
=
""
}
interface
QueryInfo
{
processType
:
number
,
authType
:
number
,
userId
:
string
}
let
queryInfo
:
QueryInfo
=
{
processType
:
1
,
authType
:
1
,
userId
:
"
123
"
}
try
{
dmInstance
.
deleteCredential
(
queryInfo
,
(
data
)
=>
{
dmInstance
.
deleteCredential
(
queryInfo
,
(
data
:
Data
)
=>
{
if
(
data
)
{
console
.
info
(
"
deleteCredential result:
"
+
JSON
.
stringify
(
data
));
}
else
{
...
...
@@ -1051,7 +1272,8 @@ deleteCredential(queryInfo: string, callback: AsyncCallback<{resultInfo: string}
}
});
}
catch
(
err
)
{
console
.
error
(
"
deleteCredential err:
"
+
err
.
code
+
"
,
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
deleteCredential err:
"
+
e
.
code
+
"
,
"
+
e
.
message
);
}
```
...
...
@@ -1074,16 +1296,27 @@ ui状态变更回调。
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
param
:
string
=
""
}
interface
TmpStr
{
verifyFailed
:
boolean
}
try
{
dmInstance
.
on
(
'
uiStateChange
'
,
(
data
)
=>
{
dmInstance
.
on
(
'
uiStateChange
'
,
(
data
:
Data
)
=>
{
console
.
log
(
"
uiStateChange executed, dialog closed
"
+
JSON
.
stringify
(
data
))
var
t
mpStr
=
JSON
.
parse
(
data
.
param
)
var
isShow
=
tmpStr
.
verifyFailed
let
tmpStr
:
T
mpStr
=
JSON
.
parse
(
data
.
param
)
let
isShow
=
tmpStr
.
verifyFailed
console
.
log
(
"
uiStateChange executed, dialog closed
"
+
isShow
)
});
}
catch
(
err
)
{
console
.
error
(
"
uiStateChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
uiStateChange errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -1106,11 +1339,14 @@ off(type: 'uiStateChange', callback?: Callback<{ param: string}>): void;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
dmInstance
.
off
(
'
uiStateChange
'
);
}
catch
(
err
)
{
console
.
error
(
"
uiStateChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
uiStateChange errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -1133,13 +1369,22 @@ on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChange
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
action
:
deviceManager
.
DeviceStateChangeAction
=
0
device
:
deviceManager
.
DeviceInfo
=
{}
}
try
{
dmInstance
.
on
(
'
deviceStateChange
'
,
(
data
)
=>
{
dmInstance
.
on
(
'
deviceStateChange
'
,
(
data
:
Data
)
=>
{
console
.
info
(
"
deviceStateChange on:
"
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
deviceStateChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
deviceStateChange errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -1162,13 +1407,22 @@ off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChang
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
action
:
deviceManager
.
DeviceStateChangeAction
=
0
device
:
deviceManager
.
DeviceInfo
=
{}
}
try
{
dmInstance
.
off
(
'
deviceStateChange
'
,
(
data
)
=>
{
dmInstance
.
off
(
'
deviceStateChange
'
,
(
data
:
Data
)
=>
{
console
.
info
(
'
deviceStateChange
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
deviceStateChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
deviceStateChange errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -1191,13 +1445,23 @@ on(type: 'deviceFound', callback: Callback<{ subscribeId: number, device: Dev
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
subscribeId
:
number
=
0
device
:
deviceManager
.
DeviceInfo
=
{}
}
subscribeId
:
number
,
device
:
DeviceInfo
try
{
dmInstance
.
on
(
'
deviceFound
'
,
(
data
)
=>
{
dmInstance
.
on
(
'
deviceFound
'
,
(
data
:
Data
)
=>
{
console
.
info
(
"
deviceFound:
"
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
deviceFound errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
deviceFound errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -1220,13 +1484,22 @@ off(type: 'deviceFound', callback?: Callback<{ subscribeId: number, device: D
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
subscribeId
:
number
=
0
device
:
deviceManager
.
DeviceInfo
=
{}
}
try
{
dmInstance
.
off
(
'
deviceFound
'
,
(
data
)
=>
{
dmInstance
.
off
(
'
deviceFound
'
,
(
data
:
Data
)
=>
{
console
.
info
(
'
deviceFound
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
deviceFound errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
deviceFound errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -1249,13 +1522,21 @@ on(type: 'discoverFail', callback: Callback<{ subscribeId: number, reason: nu
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
subscribeId
:
number
=
0
reason
:
number
=
0
}
try
{
dmInstance
.
on
(
'
discoverFail
'
,
(
data
)
=>
{
dmInstance
.
on
(
'
discoverFail
'
,
(
data
:
Data
)
=>
{
console
.
info
(
"
discoverFail on:
"
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
discoverFail errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
discoverFail errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -1278,13 +1559,21 @@ off(type: 'discoverFail', callback?: Callback<{ subscribeId: number, reason:
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
subscribeId
:
number
=
0
reason
:
number
=
0
}
try
{
dmInstance
.
off
(
'
discoverFail
'
,
(
data
)
=>
{
dmInstance
.
off
(
'
discoverFail
'
,
(
data
:
Data
)
=>
{
console
.
info
(
'
discoverFail
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
discoverFail errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
discoverFail errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -1308,13 +1597,20 @@ on(type: 'publishSuccess', callback: Callback<{ publishId: number }>): voi
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
publishId
:
number
=
0
}
try
{
dmInstance
.
on
(
'
publishSuccess
'
,
(
data
)
=>
{
dmInstance
.
on
(
'
publishSuccess
'
,
(
data
:
Data
)
=>
{
console
.
info
(
"
publishSuccess:
"
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
publishSuccess errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
publishSuccess errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -1337,13 +1633,20 @@ off(type: 'publishSuccess', callback?: Callback<{ publishId: number }>): v
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
publishId
:
number
=
0
}
try
{
dmInstance
.
off
(
'
publishSuccess
'
,
(
data
)
=>
{
dmInstance
.
off
(
'
publishSuccess
'
,
(
data
:
Data
)
=>
{
console
.
info
(
'
publishSuccess
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
publishSuccess errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
publishSuccess errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -1366,13 +1669,21 @@ on(type: 'publishFail', callback: Callback<{ publishId: number, reason: numbe
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
publishId
:
number
=
0
reason
:
number
=
0
}
try
{
dmInstance
.
on
(
'
publishFail
'
,
(
data
)
=>
{
dmInstance
.
on
(
'
publishFail
'
,
(
data
:
Data
)
=>
{
console
.
info
(
"
publishFail on:
"
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
publishFail errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
publishFail errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -1395,13 +1706,21 @@ off(type: 'publishFail', callback?: Callback<{ publishId: number, reason: num
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
publishId
:
number
=
0
reason
:
number
=
0
}
try
{
dmInstance
.
off
(
'
publishFail
'
,
(
data
)
=>
{
dmInstance
.
off
(
'
publishFail
'
,
(
data
:
Data
)
=>
{
console
.
info
(
'
publishFail
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
publishFail errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
publishFail errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -1424,13 +1743,16 @@ on(type: 'serviceDie', callback: () => void): void
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
dmInstance
.
on
(
"
serviceDie
"
,
()
=>
{
console
.
info
(
"
serviceDie on
"
);
});
}
catch
(
err
)
{
console
.
error
(
"
serviceDie errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
serviceDie errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -1453,12 +1775,15 @@ off(type: 'serviceDie', callback?: () => void): void
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
dmInstance
.
off
(
"
serviceDie
"
,
()
=>
{
console
.
info
(
"
serviceDie off
"
);
});
}
catch
(
err
)
{
console
.
error
(
"
serviceDie errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
serviceDie errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-distributedDeviceManager.md
浏览文件 @
75aaa5ed
...
...
@@ -18,7 +18,7 @@
## 导入模块
```
j
s
```
t
s
import
deviceManager
from
'
@ohos.distributedDeviceManager
'
;
```
...
...
@@ -45,11 +45,15 @@ createDeviceManager(bundleName: string): DeviceManager;
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedDeviceManager
'
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
let
dmInstance
=
deviceManager
.
createDeviceManager
(
"
ohos.samples.jshelloworld
"
);
}
catch
(
err
)
{
console
.
error
(
"
createDeviceManager errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
createDeviceManager errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -79,11 +83,14 @@ releaseDeviceManager(deviceManager: DeviceManager): void;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
deviceManager
.
releaseDeviceManager
(
dmInstance
);
}
catch
(
err
)
{
console
.
error
(
"
release device manager errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
release device manager errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -143,11 +150,15 @@ getAvailableDeviceListSync(): Array<DeviceBasicInfo>;
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedDeviceManager
'
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
var
deviceInfoList
=
dmInstance
.
getAvailableDeviceListSync
();
let
deviceInfoList
:
Array
<
deviceManager
.
eviceBasicInfo
>
=
dmInstance
.
getAvailableDeviceListSync
();
}
catch
(
err
)
{
console
.
error
(
"
getAvailableDeviceListSync errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getAvailableDeviceListSync errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -177,9 +188,12 @@ getAvailableDeviceList(callback:AsyncCallback<Array<DeviceBasicInfo>>
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedDeviceManager
'
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
dmInstance
.
getAvailableDeviceList
((
err
,
data
)
=>
{
dmInstance
.
getAvailableDeviceList
((
err
:
BusinessError
,
data
:
Array
<
deviceManager
.
DeviceBasicInfo
>
)
=>
{
if
(
err
)
{
console
.
error
(
"
getAvailableDeviceList errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
return
;
...
...
@@ -187,7 +201,8 @@ getAvailableDeviceList(callback:AsyncCallback<Array<DeviceBasicInfo>>
console
.
log
(
'
get available device info:
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
getAvailableDeviceList errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getAvailableDeviceList errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -217,10 +232,13 @@ getAvailableDeviceList(): Promise<Array<DeviceBasicInfo>>;
**示例:**
```
js
dmInstance
.
getAvailableDeviceList
().
then
((
data
)
=>
{
```
ts
import
deviceManager
from
'
@ohos.distributedDeviceManager
'
import
{
BusinessError
}
from
'
@ohos.base
'
dmInstance
.
getAvailableDeviceList
().
then
((
data
:
Array
<
deviceManager
.
DeviceBasicInfo
>
)
=>
{
console
.
log
(
'
get available device info:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
"
getAvailableDeviceList errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
});
```
...
...
@@ -251,12 +269,15 @@ getLocalDeviceNetworkId(): string;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
var
deviceNetworkId
=
dmInstance
.
getLocalDeviceNetworkId
();
let
deviceNetworkId
:
string
=
dmInstance
.
getLocalDeviceNetworkId
();
console
.
log
(
'
local device networkId:
'
+
JSON
.
stringify
(
deviceNetworkId
));
}
catch
(
err
)
{
console
.
error
(
"
getLocalDeviceNetworkId errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getLocalDeviceNetworkId errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -286,12 +307,15 @@ getLocalDeviceName(): string;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
var
deviceName
=
dmInstance
.
getLocalDeviceName
();
let
deviceName
:
string
=
dmInstance
.
getLocalDeviceName
();
console
.
log
(
'
local device name:
'
+
JSON
.
stringify
(
deviceName
));
}
catch
(
err
)
{
console
.
error
(
"
getLocalDeviceName errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getLocalDeviceName errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -321,12 +345,15 @@ getLocalDeviceType(): number;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
var
deviceType
=
dmInstance
.
getLocalDeviceType
();
let
deviceType
:
number
=
dmInstance
.
getLocalDeviceType
();
console
.
log
(
'
local device type:
'
+
JSON
.
stringify
(
deviceType
));
}
catch
(
err
)
{
console
.
error
(
"
getLocalDeviceType errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getLocalDeviceType errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -356,12 +383,15 @@ getLocalDeviceId(): string;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
var
deviceId
=
dmInstance
.
getLocalDeviceId
();
let
deviceId
:
string
=
dmInstance
.
getLocalDeviceId
();
console
.
log
(
'
local device id:
'
+
JSON
.
stringify
(
deviceId
));
}
catch
(
err
)
{
console
.
error
(
"
getLocalDeviceId errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getLocalDeviceId errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -397,14 +427,17 @@ getDeviceName(networkId: string): string;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
// 设备网络标识,可以从可信设备列表中获取
let
networkId
=
"
xxxxxxx
"
var
deviceName
=
dmInstance
.
getDeviceName
(
networkId
);
let
deviceName
:
string
=
dmInstance
.
getDeviceName
(
networkId
);
console
.
log
(
'
device name:
'
+
JSON
.
stringify
(
deviceName
));
}
catch
(
err
)
{
console
.
error
(
"
getDeviceName errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getDeviceName errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -440,14 +473,17 @@ getDeviceType(networkId: string): number;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
// 设备网络标识,可以从可信设备列表中获取
let
networkId
=
"
xxxxxxx
"
var
deviceType
=
dmInstance
.
getDeviceType
(
networkId
);
let
deviceType
:
number
=
dmInstance
.
getDeviceType
(
networkId
);
console
.
log
(
'
device type:
'
+
JSON
.
stringify
(
deviceType
));
}
catch
(
err
)
{
console
.
error
(
"
getDeviceType errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getDeviceType errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -479,20 +515,36 @@ startDiscovering(discoverParam: {[key: string]: Object} , filterOption
**示例:**
```
js
var
discoverParam
=
{
'
discoverTargetType
'
:
1
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
interface
DiscoverParam
{
discoverTargetType
:
number
}
interface
FilterOptions
{
availableStatus
:
number
,
discoverDistance
:
number
,
authenticationStatus
:
number
,
authorizationType
:
number
}
let
discoverParam
:
DiscoverParam
=
{
discoverTargetType
:
1
};
var
filterOptions
=
{
'
availableStatus
'
:
1
,
'
discoverDistance
'
:
50
,
'
authenticationStatus
'
:
0
,
'
authorizationType
'
:
0
let
filterOptions
:
FilterOptions
=
{
availableStatus
:
1
,
discoverDistance
:
50
,
authenticationStatus
:
0
,
authorizationType
:
0
};
try
{
dmInstance
.
startDiscovering
(
discoverParam
,
filterOptions
);
// 当有设备发现时,通过discoverSuccess回调通知给应用程序
}
catch
(
err
)
{
console
.
error
(
"
startDiscovering errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
startDiscovering errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -517,11 +569,14 @@ stopDiscovering(): void;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
dmInstance
.
stopDiscovering
();
}
catch
(
err
)
{
console
.
error
(
"
stopDiscovering errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
stopDiscovering errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -554,18 +609,32 @@ bindTarget(deviceId: string, bindParam: {[key: string]: Object} , call
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
deviceId
:
string
=
""
}
interface
BindParam
{
bindType
:
number
,
// 认证类型: 1 - 无帐号PIN码认证
targetPkgName
:
string
,
appName
:
string
,
appOperation
:
string
,
customDescription
:
string
}
// 认证的设备信息,可以从发现的结果中获取
var
deviceId
=
"
XXXXXXXX
"
;
let
bindParam
=
{
'
bindType
'
:
1
,
// 认证类型: 1 - 无帐号PIN码认证
'
targetPkgName
'
:
'
xxxx
'
,
'
appName
'
:
'
xxxx
'
,
'
appOperation
'
:
'
xxxx
'
,
'
customDescription
'
:
'
xxxx
'
let
deviceId
=
"
XXXXXXXX
"
;
let
bindParam
:
BindParam
=
{
bindType
:
1
,
// 认证类型: 1 - 无帐号PIN码认证
targetPkgName
:
'
xxxx
'
,
appName
:
'
xxxx
'
,
appOperation
:
'
xxxx
'
,
customDescription
:
'
xxxx
'
}
try
{
dmInstance
.
bindTarget
(
deviceId
,
bindParam
,
(
err
,
d
ata
)
=>
{
dmInstance
.
bindTarget
(
deviceId
,
bindParam
,
(
err
:
BusinessError
,
data
:
D
ata
)
=>
{
if
(
err
)
{
console
.
error
(
"
bindTarget errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
return
;
...
...
@@ -573,7 +642,8 @@ bindTarget(deviceId: string, bindParam: {[key: string]: Object} , call
console
.
info
(
"
bindTarget result:
"
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
bindTarget errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
bindTarget errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -603,12 +673,15 @@ unbindTarget(deviceId: string): void;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
var
deviceId
=
"
XXXXXXXX
"
;
let
deviceId
=
"
XXXXXXXX
"
;
dmInstance
.
unbindTarget
(
deviceId
);
}
catch
(
err
)
{
console
.
error
(
"
unbindTarget errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
unbindTarget errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -633,7 +706,9 @@ replyUiAction(action: number, actionResult: string): void;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
/*
action = 0 - 允许授权
...
...
@@ -646,7 +721,8 @@ replyUiAction(action: number, actionResult: string): void;
let
operation
=
0
;
dmInstance
.
replyUiAction
(
operation
,
"
extra
"
)
}
catch
(
err
)
{
console
.
error
(
"
replyUiAction errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
replyUiAction errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -671,16 +747,27 @@ on(type: 'replyResult', callback: Callback<{ param: string}>): void;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
param
:
string
=
""
}
interface
TmpStr
{
verifyFailed
:
boolean
}
try
{
dmInstance
.
on
(
'
replyResult
'
,
(
data
)
=>
{
dmInstance
.
on
(
'
replyResult
'
,
(
data
:
Data
)
=>
{
console
.
log
(
"
replyResult executed, dialog closed
"
+
JSON
.
stringify
(
data
))
var
t
mpStr
=
JSON
.
parse
(
data
.
param
)
var
isShow
=
tmpStr
.
verifyFailed
let
tmpStr
:
T
mpStr
=
JSON
.
parse
(
data
.
param
)
let
isShow
=
tmpStr
.
verifyFailed
console
.
log
(
"
replyResult executed, dialog closed
"
+
isShow
)
});
}
catch
(
err
)
{
console
.
error
(
"
replyResult errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
replyResult errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -705,11 +792,14 @@ off(type: 'replyResult', callback?: Callback<{ param: string}>): void;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
dmInstance
.
off
(
'
replyResult
'
);
}
catch
(
err
)
{
console
.
error
(
"
replyResult errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
replyResult errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -732,13 +822,22 @@ on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChange,
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedDeviceManager
'
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
action
:
deviceManager
.
DeviceStateChange
=
0
device
:
deviceManager
.
DeviceBasicInfo
=
{}
}
try
{
dmInstance
.
on
(
'
deviceStateChange
'
,
(
data
)
=>
{
dmInstance
.
on
(
'
deviceStateChange
'
,
(
data
:
Data
)
=>
{
console
.
info
(
"
deviceStateChange on:
"
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
deviceStateChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
deviceStateChange errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -761,13 +860,22 @@ off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChang
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedDeviceManager
'
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
action
:
deviceManager
.
DeviceStateChange
=
0
device
:
deviceManager
.
DeviceBasicInfo
=
{}
}
try
{
dmInstance
.
off
(
'
deviceStatusChange
'
,
(
data
)
=>
{
dmInstance
.
off
(
'
deviceStatusChange
'
,
(
data
:
Data
)
=>
{
console
.
info
(
'
deviceStatusChange
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
deviceStatusChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
deviceStatusChange errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -790,13 +898,21 @@ on(type: 'discoverSuccess', callback: Callback<{ device: DeviceBasicInfo }>
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedDeviceManager
'
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
device
:
deviceManager
.
DeviceBasicInfo
=
{}
}
try
{
dmInstance
.
on
(
'
discoverSuccess
'
,
(
data
)
=>
{
dmInstance
.
on
(
'
discoverSuccess
'
,
(
data
:
Data
)
=>
{
console
.
info
(
"
discoverSuccess:
"
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
discoverSuccess errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
discoverSuccess errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -819,13 +935,21 @@ off(type: 'discoverSuccess', callback?: Callback<{ device: DeviceBasicInfo }&
**示例:**
```
js
```
ts
import
deviceManager
from
'
@ohos.distributedDeviceManager
'
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
device
:
deviceManager
.
DeviceBasicInfo
=
{}
}
try
{
dmInstance
.
off
(
'
discoverSuccess
'
,
(
data
)
=>
{
dmInstance
.
off
(
'
discoverSuccess
'
,
(
data
:
Data
)
=>
{
console
.
info
(
'
discoverSuccess
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
discoverSuccess errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
discoverSuccess errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -848,13 +972,20 @@ on(type: 'deviceNameChange', callback: Callback<{ deviceName: string }>):
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
deviceName
:
string
=
""
}
try
{
dmInstance
.
on
(
'
deviceNameChange
'
,
(
data
)
=>
{
dmInstance
.
on
(
'
deviceNameChange
'
,
(
data
:
Data
)
=>
{
console
.
info
(
"
deviceNameChange on:
"
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
deviceNameChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
deviceNameChange errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -877,13 +1008,20 @@ off(type: 'deviceNameChange', callback?: Callback<{ deviceName: string }>)
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
deviceName
:
string
=
""
}
try
{
dmInstance
.
off
(
'
deviceNameChange
'
,
(
data
)
=>
{
dmInstance
.
off
(
'
deviceNameChange
'
,
(
data
:
Data
)
=>
{
console
.
info
(
'
deviceNameChange
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
deviceNameChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
deviceNameChange errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -906,13 +1044,20 @@ on(type: 'discoverFailure', callback: Callback<{ reason: number }>): void;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
reason
:
number
=
0
}
try
{
dmInstance
.
on
(
'
discoverFailure
'
,
(
data
)
=>
{
dmInstance
.
on
(
'
discoverFailure
'
,
(
data
:
Data
)
=>
{
console
.
info
(
"
discoverFailure on:
"
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
discoverFailure errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
discoverFailure errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -935,13 +1080,20 @@ off(type: 'discoverFailure', callback?: Callback<{ reason: number }>): voi
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
class
Data
{
reason
:
number
=
0
}
try
{
dmInstance
.
off
(
'
discoverFailure
'
,
(
data
)
=>
{
dmInstance
.
off
(
'
discoverFailure
'
,
(
data
:
Data
)
=>
{
console
.
info
(
'
discoverFailure
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
discoverFailure errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
discoverFailure errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -964,13 +1116,16 @@ on(type: 'serviceDie', callback?: Callback<{}>): void;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
dmInstance
.
on
(
"
serviceDie
"
,
()
=>
{
console
.
info
(
"
serviceDie on
"
);
});
}
catch
(
err
)
{
console
.
error
(
"
serviceDie errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
serviceDie errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
...
...
@@ -993,13 +1148,16 @@ off(type: 'serviceDie', callback?: Callback<{}>): void;
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
try
{
dmInstance
.
off
(
"
serviceDie
"
,
()
=>
{
console
.
info
(
"
serviceDie off
"
);
});
}
catch
(
err
)
{
console
.
error
(
"
serviceDie errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
let
e
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
serviceDie errCode:
"
+
e
.
code
+
"
,errMessage:
"
+
e
.
message
);
}
```
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录