1e41f4b71Sopenharmony_ci# @ohos.continuation.continuationManager (continuationManager) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_cicontinuationManager模块提供了流转/协同入口管理服务能力,包括连接/取消流转管理服务,注册/解注册设备连接变化监听,拉起设备选择模块,更新连接状态。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## 导入模块 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci```ts 12e41f4b71Sopenharmony_ciimport { continuationManager } from '@kit.AbilityKit'; 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## continuationManager.register<sup>(deprecated)</sup> 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ciregister(callback: AsyncCallback\<number>): void 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci注册流转管理服务,并获取对应的注册token,无过滤条件,使用AsyncCallback方式作为异步方法。 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci> **说明:** 22e41f4b71Sopenharmony_ci> 23e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[registerContinuation](#continuationmanagerregistercontinuation9)替代。 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**参数:** 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 30e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 31e41f4b71Sopenharmony_ci | callback | AsyncCallback\<number> | 是 | AsyncCallback形式返回流转管理服务连接后生成的token。 | 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci**示例:** 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci ```ts 36e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci let token: number = -1; 39e41f4b71Sopenharmony_ci continuationManager.register((err, data) => { 40e41f4b71Sopenharmony_ci if (err.code != 0) { 41e41f4b71Sopenharmony_ci console.error('register failed, cause: ' + JSON.stringify(err)); 42e41f4b71Sopenharmony_ci return; 43e41f4b71Sopenharmony_ci } 44e41f4b71Sopenharmony_ci console.info('register finished, ' + JSON.stringify(data)); 45e41f4b71Sopenharmony_ci token = data; 46e41f4b71Sopenharmony_ci }); 47e41f4b71Sopenharmony_ci ``` 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci## continuationManager.register<sup>(deprecated)</sup> 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ciregister(options: ContinuationExtraParams, callback: AsyncCallback\<number>): void 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci连接流转管理服务,并获取对应的注册token,使用AsyncCallback方式作为异步方法。 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci> **说明:** 56e41f4b71Sopenharmony_ci> 57e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[registerContinuation](#continuationmanagerregistercontinuation9-1)替代。 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**参数:** 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 64e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 65e41f4b71Sopenharmony_ci | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | 是 | 过滤可选择设备列表的额外参数。 | 66e41f4b71Sopenharmony_ci | callback | AsyncCallback\<number> | 是 | AsyncCallback形式返回流转管理服务连接后生成的token。 | 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci**示例:** 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci ```ts 71e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci let token: number = -1; 74e41f4b71Sopenharmony_ci continuationManager.register( 75e41f4b71Sopenharmony_ci { 76e41f4b71Sopenharmony_ci deviceType: ["00E"] 77e41f4b71Sopenharmony_ci }, 78e41f4b71Sopenharmony_ci (err, data) => { 79e41f4b71Sopenharmony_ci if (err.code != 0) { 80e41f4b71Sopenharmony_ci console.error('register failed, cause: ' + JSON.stringify(err)); 81e41f4b71Sopenharmony_ci return; 82e41f4b71Sopenharmony_ci } 83e41f4b71Sopenharmony_ci console.info('register finished, ' + JSON.stringify(data)); 84e41f4b71Sopenharmony_ci token = data; 85e41f4b71Sopenharmony_ci }); 86e41f4b71Sopenharmony_ci ``` 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci## continuationManager.register<sup>(deprecated)</sup> 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ciregister(options?: ContinuationExtraParams): Promise\<number> 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci连接流转管理服务,并获取对应的注册token,使用Promise方式作为异步方法。 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci> **说明:** 95e41f4b71Sopenharmony_ci> 96e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[registerContinuation](#continuationmanagerregistercontinuation9-2)替代。 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**参数:** 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 103e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 104e41f4b71Sopenharmony_ci | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | 否 | 过滤可选择设备列表的额外参数,该参数可缺省| 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci**返回值:** 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci| 类型 | 说明 | 109e41f4b71Sopenharmony_ci| ------------------------- | ------------------ | 110e41f4b71Sopenharmony_ci| Promise\<number> | Promise形式返回流转管理服务连接后生成的token。 | 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci**示例:** 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci ```ts 115e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 116e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci let token: number = -1; 119e41f4b71Sopenharmony_ci continuationManager.register( 120e41f4b71Sopenharmony_ci { deviceType: ["00E"] }).then((data) => { 121e41f4b71Sopenharmony_ci console.info('register finished, ' + JSON.stringify(data)); 122e41f4b71Sopenharmony_ci token = data; 123e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 124e41f4b71Sopenharmony_ci console.error('register failed, cause: ' + JSON.stringify(err)); 125e41f4b71Sopenharmony_ci }); 126e41f4b71Sopenharmony_ci ``` 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci## continuationManager.registerContinuation<sup>9+</sup> 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ciregisterContinuation(callback: AsyncCallback\<number>): void 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci注册流转管理服务,并获取对应的注册token,无过滤条件,使用AsyncCallback方式作为异步方法。 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci**参数:** 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 143e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 144e41f4b71Sopenharmony_ci | callback | AsyncCallback\<number> | 是 | AsyncCallback形式返回流转管理服务连接后生成的token。 | 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci**错误码:** 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 151e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 152e41f4b71Sopenharmony_ci| 201 | Permission denied.| 153e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 154e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 155e41f4b71Sopenharmony_ci| 16600003 | The number of token registration times has reached the upper limit. | 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci**示例:** 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci ```ts 160e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci let token: number = -1; 163e41f4b71Sopenharmony_ci try { 164e41f4b71Sopenharmony_ci continuationManager.registerContinuation((err, data) => { 165e41f4b71Sopenharmony_ci if (err.code != 0) { 166e41f4b71Sopenharmony_ci console.error('registerContinuation failed, cause: ' + JSON.stringify(err)); 167e41f4b71Sopenharmony_ci return; 168e41f4b71Sopenharmony_ci } 169e41f4b71Sopenharmony_ci console.info('registerContinuation finished, ' + JSON.stringify(data)); 170e41f4b71Sopenharmony_ci token = data; 171e41f4b71Sopenharmony_ci }); 172e41f4b71Sopenharmony_ci } catch (err) { 173e41f4b71Sopenharmony_ci console.error('registerContinuation failed, cause: ' + JSON.stringify(err)); 174e41f4b71Sopenharmony_ci } 175e41f4b71Sopenharmony_ci ``` 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci## continuationManager.registerContinuation<sup>9+</sup> 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ciregisterContinuation(options: ContinuationExtraParams, callback: AsyncCallback\<number>): void 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci连接流转管理服务,并获取对应的注册token,使用AsyncCallback方式作为异步方法。 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci**参数:** 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 192e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 193e41f4b71Sopenharmony_ci | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | 是 | 过滤可选择设备列表的额外参数。 | 194e41f4b71Sopenharmony_ci | callback | AsyncCallback\<number> | 是 | AsyncCallback形式返回流转管理服务连接后生成的token。 | 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci**错误码:** 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 201e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 202e41f4b71Sopenharmony_ci| 201 | Permission denied.| 203e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 204e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 205e41f4b71Sopenharmony_ci| 16600003 | The number of token registration times has reached the upper limit. | 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci**示例:** 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci ```ts 210e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci let token: number = -1; 213e41f4b71Sopenharmony_ci try { 214e41f4b71Sopenharmony_ci continuationManager.registerContinuation( 215e41f4b71Sopenharmony_ci { 216e41f4b71Sopenharmony_ci deviceType: ["00E"] 217e41f4b71Sopenharmony_ci }, 218e41f4b71Sopenharmony_ci (err, data) => { 219e41f4b71Sopenharmony_ci if (err.code != 0) { 220e41f4b71Sopenharmony_ci console.error('registerContinuation failed, cause: ' + JSON.stringify(err)); 221e41f4b71Sopenharmony_ci return; 222e41f4b71Sopenharmony_ci } 223e41f4b71Sopenharmony_ci console.info('registerContinuation finished, ' + JSON.stringify(data)); 224e41f4b71Sopenharmony_ci token = data; 225e41f4b71Sopenharmony_ci }); 226e41f4b71Sopenharmony_ci } catch (err) { 227e41f4b71Sopenharmony_ci console.error('registerContinuation failed, cause: ' + JSON.stringify(err)); 228e41f4b71Sopenharmony_ci } 229e41f4b71Sopenharmony_ci ``` 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci## continuationManager.registerContinuation<sup>9+</sup> 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ciregisterContinuation(options?: ContinuationExtraParams): Promise\<number> 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci连接流转管理服务,并获取对应的注册token,使用Promise方式作为异步方法。 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci**参数:** 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 246e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 247e41f4b71Sopenharmony_ci | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | 否 | 过滤可选择设备列表的额外参数,该参数可缺省| 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci**返回值:** 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci| 类型 | 说明 | 252e41f4b71Sopenharmony_ci| ------------------------- | ------------------ | 253e41f4b71Sopenharmony_ci| Promise\<number> | Promise形式返回流转管理服务连接后生成的token。 | 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci**错误码:** 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 260e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 261e41f4b71Sopenharmony_ci| 201 | Permission denied.| 262e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed. | 263e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 264e41f4b71Sopenharmony_ci| 16600003 | The number of token registration times has reached the upper limit. | 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci**示例:** 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci ```ts 269e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 270e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci let token: number = -1; 273e41f4b71Sopenharmony_ci try { 274e41f4b71Sopenharmony_ci continuationManager.registerContinuation( 275e41f4b71Sopenharmony_ci { 276e41f4b71Sopenharmony_ci deviceType: ["00E"] 277e41f4b71Sopenharmony_ci }).then((data) => { 278e41f4b71Sopenharmony_ci console.info('registerContinuation finished, ' + JSON.stringify(data)); 279e41f4b71Sopenharmony_ci token = data; 280e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 281e41f4b71Sopenharmony_ci console.error('registerContinuation failed, cause: ' + JSON.stringify(err)); 282e41f4b71Sopenharmony_ci }); 283e41f4b71Sopenharmony_ci } catch (err) { 284e41f4b71Sopenharmony_ci console.error('registerContinuation failed, cause: ' + JSON.stringify(err)); 285e41f4b71Sopenharmony_ci } 286e41f4b71Sopenharmony_ci ``` 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci## continuationManager.on('deviceConnect')<sup>(deprecated)</sup> 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_cion(type: 'deviceConnect', callback: Callback\<ContinuationResult>): void 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci异步方法,监听设备连接状态,使用Callback形式返回连接的设备信息。 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci> **说明:** 296e41f4b71Sopenharmony_ci> 297e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[on](#continuationmanagerondeviceselected9)替代。 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_ci**参数:** 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 304e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 305e41f4b71Sopenharmony_ci | type | string | 是 | 监听的事件类型,固定值"deviceConnect"。 | 306e41f4b71Sopenharmony_ci | callback | Callback\<[ContinuationResult](js-apis-continuation-continuationResult.md)> | 是 | 当用户从设备选择模块中选择设备时调用,返回设备ID、设备类型和设备名称供开发者使用。 | 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci**示例:** 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci ```ts 311e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 312e41f4b71Sopenharmony_ci 313e41f4b71Sopenharmony_ci continuationManager.on("deviceConnect", (data) => { 314e41f4b71Sopenharmony_ci console.info('onDeviceConnect deviceId: ' + JSON.stringify(data.id)); 315e41f4b71Sopenharmony_ci console.info('onDeviceConnect deviceType: ' + JSON.stringify(data.type)); 316e41f4b71Sopenharmony_ci console.info('onDeviceConnect deviceName: ' + JSON.stringify(data.name)); 317e41f4b71Sopenharmony_ci }); 318e41f4b71Sopenharmony_ci ``` 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci## continuationManager.on('deviceDisconnect')<sup>(deprecated)</sup> 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_cion(type: 'deviceDisconnect', callback: Callback\<string>): void 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci异步方法,监听设备断开状态,使用Callback形式返回断开的设备信息。 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci> **说明:** 327e41f4b71Sopenharmony_ci> 328e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[on](#continuationmanagerondeviceunselected9)替代。 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci**参数:** 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 335e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 336e41f4b71Sopenharmony_ci | type | string | 是 | 监听的事件类型,固定值"deviceDisconnect"。 | 337e41f4b71Sopenharmony_ci | callback | Callback\<string> | 是 | 当用户从设备选择模块中断开设备时调用,返回设备ID供开发者使用。 | 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci**示例:** 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci ```ts 342e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci continuationManager.on("deviceDisconnect", (data) => { 345e41f4b71Sopenharmony_ci console.info('onDeviceDisconnect deviceId: ' + JSON.stringify(data)); 346e41f4b71Sopenharmony_ci }); 347e41f4b71Sopenharmony_ci ``` 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci## continuationManager.off('deviceConnect')<sup>(deprecated)</sup> 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_cioff(type: 'deviceConnect', callback?: Callback\<ContinuationResult>): void 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci异步方法,取消监听设备连接状态,使用Callback形式返回连接的设备信息。 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ci> **说明:** 356e41f4b71Sopenharmony_ci> 357e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[off](#continuationmanageroffdeviceselected9)替代。 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci**参数:** 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 364e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 365e41f4b71Sopenharmony_ci | type | string | 是 | 取消监听的事件类型,固定值"deviceConnect"。 | 366e41f4b71Sopenharmony_ci | callback | Callback\<[ContinuationResult](js-apis-continuation-continuationResult.md)> | 否 | 当用户从设备选择模块中选择设备时调用,返回设备ID、设备类型和设备名称供开发者使用。 | 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci**示例:** 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci ```ts 371e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci continuationManager.off("deviceConnect", (data) => { 374e41f4b71Sopenharmony_ci console.info('onDeviceConnect deviceId: ' + JSON.stringify(data.id)); 375e41f4b71Sopenharmony_ci console.info('onDeviceConnect deviceType: ' + JSON.stringify(data.type)); 376e41f4b71Sopenharmony_ci console.info('onDeviceConnect deviceName: ' + JSON.stringify(data.name)); 377e41f4b71Sopenharmony_ci }); 378e41f4b71Sopenharmony_ci ``` 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci## continuationManager.off('deviceDisconnect')<sup>(deprecated)</sup> 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_cioff(type: 'deviceDisconnect', callback?: Callback\<string>): void 383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ci异步方法,取消监听设备断开状态,使用Callback形式返回连接的设备信息。 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ci> **说明:** 387e41f4b71Sopenharmony_ci> 388e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[off](#continuationmanageroffdeviceunselected9)替代。 389e41f4b71Sopenharmony_ci 390e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_ci**参数:** 393e41f4b71Sopenharmony_ci 394e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 395e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 396e41f4b71Sopenharmony_ci | type | string | 是 | 取消监听的事件类型,固定值"deviceDisconnect"。 | 397e41f4b71Sopenharmony_ci | callback | Callback\<string> | 否 | 当用户从设备选择模块中断开设备时调用,返回设备ID供开发者使用。 | 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci**示例:** 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci ```ts 402e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ci continuationManager.off("deviceDisconnect", (data) => { 405e41f4b71Sopenharmony_ci console.info('onDeviceDisconnect deviceId: ' + JSON.stringify(data)); 406e41f4b71Sopenharmony_ci }); 407e41f4b71Sopenharmony_ci ``` 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci## continuationManager.on('deviceSelected')<sup>9+</sup> 410e41f4b71Sopenharmony_ci 411e41f4b71Sopenharmony_cion(type: 'deviceSelected', token: number, callback: Callback\<Array\<ContinuationResult>>): void 412e41f4b71Sopenharmony_ci 413e41f4b71Sopenharmony_ci异步方法,监听设备连接状态,使用Callback形式返回连接的设备信息。 414e41f4b71Sopenharmony_ci 415e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 420e41f4b71Sopenharmony_ci 421e41f4b71Sopenharmony_ci**参数:** 422e41f4b71Sopenharmony_ci 423e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 424e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 425e41f4b71Sopenharmony_ci | type | string | 是 | 监听的事件类型,固定值"deviceSelected"。 | 426e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 427e41f4b71Sopenharmony_ci | callback | Callback\<Array\<[ContinuationResult](js-apis-continuation-continuationResult.md)>> | 是 | 当用户从设备选择模块中选择设备时调用,返回设备ID、设备类型和设备名称供开发者使用。 | 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ci**错误码:** 430e41f4b71Sopenharmony_ci 431e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 434e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 435e41f4b71Sopenharmony_ci| 201 | Permission denied.| 436e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 437e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 438e41f4b71Sopenharmony_ci| 16600002 | The specified token or callback is not registered. | 439e41f4b71Sopenharmony_ci| 16600004 | The specified callback has been registered. | 440e41f4b71Sopenharmony_ci 441e41f4b71Sopenharmony_ci**示例:** 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_ci ```ts 444e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_ci let token: number = 1; 447e41f4b71Sopenharmony_ci try { 448e41f4b71Sopenharmony_ci continuationManager.on("deviceSelected", token, (data) => { 449e41f4b71Sopenharmony_ci console.info('onDeviceSelected len: ' + data.length); 450e41f4b71Sopenharmony_ci for (let i = 0; i < data.length; i++) { 451e41f4b71Sopenharmony_ci console.info('onDeviceSelected deviceId: ' + JSON.stringify(data[i].id)); 452e41f4b71Sopenharmony_ci console.info('onDeviceSelected deviceType: ' + JSON.stringify(data[i].type)); 453e41f4b71Sopenharmony_ci console.info('onDeviceSelected deviceName: ' + JSON.stringify(data[i].name)); 454e41f4b71Sopenharmony_ci } 455e41f4b71Sopenharmony_ci }); 456e41f4b71Sopenharmony_ci } catch (err) { 457e41f4b71Sopenharmony_ci console.error('on failed, cause: ' + JSON.stringify(err)); 458e41f4b71Sopenharmony_ci } 459e41f4b71Sopenharmony_ci ``` 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci## continuationManager.on('deviceUnselected')<sup>9+</sup> 462e41f4b71Sopenharmony_ci 463e41f4b71Sopenharmony_cion(type: 'deviceUnselected', token: number, callback: Callback\<Array\<ContinuationResult>>): void 464e41f4b71Sopenharmony_ci 465e41f4b71Sopenharmony_ci异步方法,监听设备断开状态,使用Callback形式返回断开的设备信息。 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 470e41f4b71Sopenharmony_ci 471e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci**参数:** 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 476e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 477e41f4b71Sopenharmony_ci | type | string | 是 | 监听的事件类型,固定值"deviceUnselected"。 | 478e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 479e41f4b71Sopenharmony_ci | callback | Callback\<Array\<[ContinuationResult](js-apis-continuation-continuationResult.md)>> | 是 | 当用户从设备选择模块中断开设备时调用,返回设备ID、设备类型和设备名称供开发者使用。 | 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci**错误码:** 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 486e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 487e41f4b71Sopenharmony_ci| 201 | Permission denied.| 488e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 489e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 490e41f4b71Sopenharmony_ci| 16600002 | The specified token or callback is not registered. | 491e41f4b71Sopenharmony_ci| 16600004 | The specified callback has been registered. | 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci**示例:** 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_ci ```ts 496e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 497e41f4b71Sopenharmony_ci 498e41f4b71Sopenharmony_ci let token: number = 1; 499e41f4b71Sopenharmony_ci try { 500e41f4b71Sopenharmony_ci continuationManager.on("deviceUnselected", token, (data) => { 501e41f4b71Sopenharmony_ci console.info('onDeviceUnselected len: ' + data.length); 502e41f4b71Sopenharmony_ci for (let i = 0; i < data.length; i++) { 503e41f4b71Sopenharmony_ci console.info('onDeviceUnselected deviceId: ' + JSON.stringify(data[i].id)); 504e41f4b71Sopenharmony_ci console.info('onDeviceUnselected deviceType: ' + JSON.stringify(data[i].type)); 505e41f4b71Sopenharmony_ci console.info('onDeviceUnselected deviceName: ' + JSON.stringify(data[i].name)); 506e41f4b71Sopenharmony_ci } 507e41f4b71Sopenharmony_ci console.info('onDeviceUnselected finished.'); 508e41f4b71Sopenharmony_ci }); 509e41f4b71Sopenharmony_ci } catch (err) { 510e41f4b71Sopenharmony_ci console.error('on failed, cause: ' + JSON.stringify(err)); 511e41f4b71Sopenharmony_ci } 512e41f4b71Sopenharmony_ci ``` 513e41f4b71Sopenharmony_ci 514e41f4b71Sopenharmony_ci## continuationManager.off('deviceSelected')<sup>9+</sup> 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_cioff(type: 'deviceSelected', token: number): void 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_ci取消监听设备连接状态。 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 521e41f4b71Sopenharmony_ci 522e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 523e41f4b71Sopenharmony_ci 524e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 525e41f4b71Sopenharmony_ci 526e41f4b71Sopenharmony_ci**参数:** 527e41f4b71Sopenharmony_ci 528e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 529e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 530e41f4b71Sopenharmony_ci | type | string | 是 | 取消监听的事件类型,固定值"deviceSelected"。 | 531e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_ci**错误码:** 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 536e41f4b71Sopenharmony_ci 537e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 538e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 539e41f4b71Sopenharmony_ci| 201 | Permission denied.| 540e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 541e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 542e41f4b71Sopenharmony_ci| 16600002 | The specified token or callback is not registered. | 543e41f4b71Sopenharmony_ci| 16600004 | The specified callback has been registered. | 544e41f4b71Sopenharmony_ci 545e41f4b71Sopenharmony_ci**示例:** 546e41f4b71Sopenharmony_ci 547e41f4b71Sopenharmony_ci ```ts 548e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 549e41f4b71Sopenharmony_ci 550e41f4b71Sopenharmony_ci let token: number = 1; 551e41f4b71Sopenharmony_ci try { 552e41f4b71Sopenharmony_ci continuationManager.off("deviceSelected", token); 553e41f4b71Sopenharmony_ci } catch (err) { 554e41f4b71Sopenharmony_ci console.error('off failed, cause: ' + JSON.stringify(err)); 555e41f4b71Sopenharmony_ci } 556e41f4b71Sopenharmony_ci ``` 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_ci## continuationManager.off('deviceUnselected')<sup>9+</sup> 559e41f4b71Sopenharmony_ci 560e41f4b71Sopenharmony_cioff(type: 'deviceUnselected', token: number): void 561e41f4b71Sopenharmony_ci 562e41f4b71Sopenharmony_ci取消监听设备断开状态。 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 565e41f4b71Sopenharmony_ci 566e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 567e41f4b71Sopenharmony_ci 568e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 569e41f4b71Sopenharmony_ci 570e41f4b71Sopenharmony_ci**参数:** 571e41f4b71Sopenharmony_ci 572e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 573e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 574e41f4b71Sopenharmony_ci | type | string | 是 | 取消监听的事件类型,固定值"deviceUnselected"。 | 575e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 576e41f4b71Sopenharmony_ci 577e41f4b71Sopenharmony_ci**错误码:** 578e41f4b71Sopenharmony_ci 579e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 580e41f4b71Sopenharmony_ci 581e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 582e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 583e41f4b71Sopenharmony_ci| 201 | Permission denied.| 584e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 585e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 586e41f4b71Sopenharmony_ci| 16600002 | The specified token or callback is not registered. | 587e41f4b71Sopenharmony_ci| 16600004 | The specified callback has been registered. | 588e41f4b71Sopenharmony_ci 589e41f4b71Sopenharmony_ci**示例:** 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci ```ts 592e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 593e41f4b71Sopenharmony_ci 594e41f4b71Sopenharmony_ci let token: number = 1; 595e41f4b71Sopenharmony_ci try { 596e41f4b71Sopenharmony_ci continuationManager.off("deviceUnselected", token); 597e41f4b71Sopenharmony_ci } catch (err) { 598e41f4b71Sopenharmony_ci console.error('off failed, cause: ' + JSON.stringify(err)); 599e41f4b71Sopenharmony_ci } 600e41f4b71Sopenharmony_ci ``` 601e41f4b71Sopenharmony_ci 602e41f4b71Sopenharmony_ci## continuationManager.startDeviceManager<sup>(deprecated)</sup> 603e41f4b71Sopenharmony_ci 604e41f4b71Sopenharmony_cistartDeviceManager(token: number, callback: AsyncCallback\<void>): void 605e41f4b71Sopenharmony_ci 606e41f4b71Sopenharmony_ci拉起设备选择模块,可显示组网内可选择设备列表信息,无过滤条件,使用AsyncCallback方式作为异步方法。 607e41f4b71Sopenharmony_ci 608e41f4b71Sopenharmony_ci> **说明:** 609e41f4b71Sopenharmony_ci> 610e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[startContinuationDeviceManager](#continuationmanagerstartcontinuationdevicemanager9)替代。 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ci**参数:** 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 617e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 618e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 619e41f4b71Sopenharmony_ci | callback | AsyncCallback\<void> | 是 | 回调函数。当模块选择完成,err为undefined,否则返回错误对象。 | 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci**示例:** 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ci ```ts 624e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 625e41f4b71Sopenharmony_ci 626e41f4b71Sopenharmony_ci let token: number = 1; 627e41f4b71Sopenharmony_ci continuationManager.startDeviceManager(token, (err) => { 628e41f4b71Sopenharmony_ci if (err.code != 0) { 629e41f4b71Sopenharmony_ci console.error('startDeviceManager failed, cause: ' + JSON.stringify(err)); 630e41f4b71Sopenharmony_ci return; 631e41f4b71Sopenharmony_ci } 632e41f4b71Sopenharmony_ci console.info('startDeviceManager finished. '); 633e41f4b71Sopenharmony_ci }); 634e41f4b71Sopenharmony_ci ``` 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_ci## continuationManager.startDeviceManager<sup>(deprecated)</sup> 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_cistartDeviceManager(token: number, options: ContinuationExtraParams, callback: AsyncCallback\<void>): void 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_ci拉起设备选择模块,可显示组网内可选择设备列表信息,使用AsyncCallback方式作为异步方法。 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_ci> **说明:** 643e41f4b71Sopenharmony_ci> 644e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[startContinuationDeviceManager](#continuationmanagerstartcontinuationdevicemanager9-1)替代。 645e41f4b71Sopenharmony_ci 646e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 647e41f4b71Sopenharmony_ci 648e41f4b71Sopenharmony_ci**参数:** 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 651e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 652e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 653e41f4b71Sopenharmony_ci | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | 是 | 过滤可选择设备列表的额外参数。 | 654e41f4b71Sopenharmony_ci | callback | AsyncCallback\<void> | 是 | 回调函数。当模块选择完成,err为undefined,否则返回错误对象。 | 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_ci**示例:** 657e41f4b71Sopenharmony_ci 658e41f4b71Sopenharmony_ci ```ts 659e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 660e41f4b71Sopenharmony_ci 661e41f4b71Sopenharmony_ci let token: number = 1; 662e41f4b71Sopenharmony_ci continuationManager.startDeviceManager( 663e41f4b71Sopenharmony_ci token, 664e41f4b71Sopenharmony_ci { 665e41f4b71Sopenharmony_ci deviceType: ["00E"] 666e41f4b71Sopenharmony_ci }, 667e41f4b71Sopenharmony_ci (err) => { 668e41f4b71Sopenharmony_ci if (err.code != 0) { 669e41f4b71Sopenharmony_ci console.error('startDeviceManager failed, cause: ' + JSON.stringify(err)); 670e41f4b71Sopenharmony_ci return; 671e41f4b71Sopenharmony_ci } 672e41f4b71Sopenharmony_ci console.info('startDeviceManager finished. '); 673e41f4b71Sopenharmony_ci }); 674e41f4b71Sopenharmony_ci ``` 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_ci## continuationManager.startDeviceManager<sup>(deprecated)</sup> 677e41f4b71Sopenharmony_ci 678e41f4b71Sopenharmony_cistartDeviceManager(token: number, options?: ContinuationExtraParams): Promise\<void> 679e41f4b71Sopenharmony_ci 680e41f4b71Sopenharmony_ci拉起设备选择模块,可显示组网内可选择设备列表信息,使用Promise方式作为异步方法。 681e41f4b71Sopenharmony_ci 682e41f4b71Sopenharmony_ci> **说明:** 683e41f4b71Sopenharmony_ci> 684e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[startContinuationDeviceManager](#continuationmanagerstartcontinuationdevicemanager9-2)替代。 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 687e41f4b71Sopenharmony_ci 688e41f4b71Sopenharmony_ci**参数:** 689e41f4b71Sopenharmony_ci 690e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 691e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 692e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 693e41f4b71Sopenharmony_ci | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | 否 | 过滤可选择设备列表的额外参数,该参数可缺省| 694e41f4b71Sopenharmony_ci 695e41f4b71Sopenharmony_ci**返回值:** 696e41f4b71Sopenharmony_ci 697e41f4b71Sopenharmony_ci| 类型 | 说明 | 698e41f4b71Sopenharmony_ci| ------------------------- | ------------------ | 699e41f4b71Sopenharmony_ci| Promise\<void> | Promise形式返回接口调用结果。 | 700e41f4b71Sopenharmony_ci 701e41f4b71Sopenharmony_ci**示例:** 702e41f4b71Sopenharmony_ci 703e41f4b71Sopenharmony_ci ```ts 704e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 705e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 706e41f4b71Sopenharmony_ci 707e41f4b71Sopenharmony_ci let token: number = -1; 708e41f4b71Sopenharmony_ci continuationManager.startDeviceManager( 709e41f4b71Sopenharmony_ci token, 710e41f4b71Sopenharmony_ci { 711e41f4b71Sopenharmony_ci deviceType: ["00E"] 712e41f4b71Sopenharmony_ci }).then(() => { 713e41f4b71Sopenharmony_ci console.info('startDeviceManager finished. '); 714e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 715e41f4b71Sopenharmony_ci console.error('startDeviceManager failed, cause: ' + JSON.stringify(err)); 716e41f4b71Sopenharmony_ci }); 717e41f4b71Sopenharmony_ci ``` 718e41f4b71Sopenharmony_ci 719e41f4b71Sopenharmony_ci## continuationManager.startContinuationDeviceManager<sup>9+</sup> 720e41f4b71Sopenharmony_ci 721e41f4b71Sopenharmony_cistartContinuationDeviceManager(token: number, callback: AsyncCallback\<void>): void 722e41f4b71Sopenharmony_ci 723e41f4b71Sopenharmony_ci拉起设备选择模块,可显示组网内可选择设备列表信息,无过滤条件,使用AsyncCallback方式作为异步方法。 724e41f4b71Sopenharmony_ci 725e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 728e41f4b71Sopenharmony_ci 729e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 730e41f4b71Sopenharmony_ci 731e41f4b71Sopenharmony_ci**参数:** 732e41f4b71Sopenharmony_ci 733e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 734e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 735e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 736e41f4b71Sopenharmony_ci | callback | AsyncCallback\<void> | 是 | 回调函数。当模块选择完成,err为undefined,否则返回错误对象。 | 737e41f4b71Sopenharmony_ci 738e41f4b71Sopenharmony_ci**错误码:** 739e41f4b71Sopenharmony_ci 740e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 741e41f4b71Sopenharmony_ci 742e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 743e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 744e41f4b71Sopenharmony_ci| 201 | Permission denied.| 745e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 746e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 747e41f4b71Sopenharmony_ci| 16600002 | The specified token or callback is not registered. | 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ci**示例:** 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ci ```ts 752e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 753e41f4b71Sopenharmony_ci 754e41f4b71Sopenharmony_ci let token: number = -1; 755e41f4b71Sopenharmony_ci try { 756e41f4b71Sopenharmony_ci continuationManager.startContinuationDeviceManager(token, (err) => { 757e41f4b71Sopenharmony_ci if (err.code != 0) { 758e41f4b71Sopenharmony_ci console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err)); 759e41f4b71Sopenharmony_ci return; 760e41f4b71Sopenharmony_ci } 761e41f4b71Sopenharmony_ci console.info('startContinuationDeviceManager finished. '); 762e41f4b71Sopenharmony_ci }); 763e41f4b71Sopenharmony_ci } catch (err) { 764e41f4b71Sopenharmony_ci console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err)); 765e41f4b71Sopenharmony_ci } 766e41f4b71Sopenharmony_ci ``` 767e41f4b71Sopenharmony_ci 768e41f4b71Sopenharmony_ci## continuationManager.startContinuationDeviceManager<sup>9+</sup> 769e41f4b71Sopenharmony_ci 770e41f4b71Sopenharmony_cistartContinuationDeviceManager(token: number, options: ContinuationExtraParams, callback: AsyncCallback\<void>): void 771e41f4b71Sopenharmony_ci 772e41f4b71Sopenharmony_ci拉起设备选择模块,可显示组网内可选择设备列表信息,使用AsyncCallback方式作为异步方法。 773e41f4b71Sopenharmony_ci 774e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 775e41f4b71Sopenharmony_ci 776e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 777e41f4b71Sopenharmony_ci 778e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 779e41f4b71Sopenharmony_ci 780e41f4b71Sopenharmony_ci**参数:** 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 783e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 784e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 785e41f4b71Sopenharmony_ci | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | 是 | 过滤可选择设备列表的额外参数。 | 786e41f4b71Sopenharmony_ci | callback | AsyncCallback\<void> | 是 | 回调函数。当模块选择完成,err为undefined,否则返回错误对象。 | 787e41f4b71Sopenharmony_ci 788e41f4b71Sopenharmony_ci**错误码:** 789e41f4b71Sopenharmony_ci 790e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 791e41f4b71Sopenharmony_ci 792e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 793e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 794e41f4b71Sopenharmony_ci| 201 | Permission denied.| 795e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 796e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 797e41f4b71Sopenharmony_ci| 16600002 | The specified token or callback is not registered. | 798e41f4b71Sopenharmony_ci 799e41f4b71Sopenharmony_ci**示例:** 800e41f4b71Sopenharmony_ci 801e41f4b71Sopenharmony_ci ```ts 802e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 803e41f4b71Sopenharmony_ci 804e41f4b71Sopenharmony_ci let token: number = -1; 805e41f4b71Sopenharmony_ci try { 806e41f4b71Sopenharmony_ci continuationManager.startContinuationDeviceManager( 807e41f4b71Sopenharmony_ci token, 808e41f4b71Sopenharmony_ci { 809e41f4b71Sopenharmony_ci deviceType: ["00E"] 810e41f4b71Sopenharmony_ci }, 811e41f4b71Sopenharmony_ci (err) => { 812e41f4b71Sopenharmony_ci if (err.code != 0) { 813e41f4b71Sopenharmony_ci console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err)); 814e41f4b71Sopenharmony_ci return; 815e41f4b71Sopenharmony_ci } 816e41f4b71Sopenharmony_ci console.info('startContinuationDeviceManager finished. '); 817e41f4b71Sopenharmony_ci }); 818e41f4b71Sopenharmony_ci } catch (err) { 819e41f4b71Sopenharmony_ci console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err)); 820e41f4b71Sopenharmony_ci } 821e41f4b71Sopenharmony_ci ``` 822e41f4b71Sopenharmony_ci 823e41f4b71Sopenharmony_ci## continuationManager.startContinuationDeviceManager<sup>9+</sup> 824e41f4b71Sopenharmony_ci 825e41f4b71Sopenharmony_cistartContinuationDeviceManager(token: number, options?: ContinuationExtraParams): Promise\<void> 826e41f4b71Sopenharmony_ci 827e41f4b71Sopenharmony_ci拉起设备选择模块,可显示组网内可选择设备列表信息,使用Promise方式作为异步方法。 828e41f4b71Sopenharmony_ci 829e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 830e41f4b71Sopenharmony_ci 831e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 832e41f4b71Sopenharmony_ci 833e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 834e41f4b71Sopenharmony_ci 835e41f4b71Sopenharmony_ci**参数:** 836e41f4b71Sopenharmony_ci 837e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 838e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 839e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 840e41f4b71Sopenharmony_ci | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | 否 | 过滤可选择设备列表的额外参数,该参数可缺省| 841e41f4b71Sopenharmony_ci 842e41f4b71Sopenharmony_ci**返回值:** 843e41f4b71Sopenharmony_ci 844e41f4b71Sopenharmony_ci| 类型 | 说明 | 845e41f4b71Sopenharmony_ci| ------------------------- | ------------------ | 846e41f4b71Sopenharmony_ci| Promise\<void> | Promise形式返回接口调用结果。 | 847e41f4b71Sopenharmony_ci 848e41f4b71Sopenharmony_ci**错误码:** 849e41f4b71Sopenharmony_ci 850e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 851e41f4b71Sopenharmony_ci 852e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 853e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 854e41f4b71Sopenharmony_ci| 201 | Permission denied.| 855e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed. | 856e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 857e41f4b71Sopenharmony_ci| 16600002 | The specified token or callback is not registered. | 858e41f4b71Sopenharmony_ci 859e41f4b71Sopenharmony_ci**示例:** 860e41f4b71Sopenharmony_ci 861e41f4b71Sopenharmony_ci ```ts 862e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 863e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 864e41f4b71Sopenharmony_ci 865e41f4b71Sopenharmony_ci let token: number = -1; 866e41f4b71Sopenharmony_ci try { 867e41f4b71Sopenharmony_ci continuationManager.startContinuationDeviceManager( 868e41f4b71Sopenharmony_ci token, 869e41f4b71Sopenharmony_ci { 870e41f4b71Sopenharmony_ci deviceType: ["00E"] 871e41f4b71Sopenharmony_ci }).then(() => { 872e41f4b71Sopenharmony_ci console.info('startContinuationDeviceManager finished. '); 873e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 874e41f4b71Sopenharmony_ci console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err)); 875e41f4b71Sopenharmony_ci }); 876e41f4b71Sopenharmony_ci } catch (err) { 877e41f4b71Sopenharmony_ci console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err)); 878e41f4b71Sopenharmony_ci } 879e41f4b71Sopenharmony_ci ``` 880e41f4b71Sopenharmony_ci 881e41f4b71Sopenharmony_ci## continuationManager.updateConnectStatus<sup>(deprecated)</sup> 882e41f4b71Sopenharmony_ci 883e41f4b71Sopenharmony_ciupdateConnectStatus(token: number, deviceId: string, status: DeviceConnectState, callback: AsyncCallback\<void>): void 884e41f4b71Sopenharmony_ci 885e41f4b71Sopenharmony_ci通知设备选择模块,更新当前的连接状态,使用AsyncCallback方式作为异步方法。 886e41f4b71Sopenharmony_ci 887e41f4b71Sopenharmony_ci> **说明:** 888e41f4b71Sopenharmony_ci> 889e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[updateContinuationState](#continuationmanagerupdatecontinuationstate9)替代。 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 892e41f4b71Sopenharmony_ci 893e41f4b71Sopenharmony_ci**参数:** 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 896e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 897e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 898e41f4b71Sopenharmony_ci | deviceId | string | 是 | 设备ID。 | 899e41f4b71Sopenharmony_ci | status | [DeviceConnectState](#deviceconnectstate) | 是 | 设备连接状态。 | 900e41f4b71Sopenharmony_ci | callback | AsyncCallback\<void> | 是 | 回调函数。当通知设备成功,err为undefined,否则返回错误对象。 | 901e41f4b71Sopenharmony_ci 902e41f4b71Sopenharmony_ci**示例:** 903e41f4b71Sopenharmony_ci 904e41f4b71Sopenharmony_ci ```ts 905e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 906e41f4b71Sopenharmony_ci 907e41f4b71Sopenharmony_ci let token: number = -1; 908e41f4b71Sopenharmony_ci let deviceId: string = "test deviceId"; 909e41f4b71Sopenharmony_ci continuationManager.updateConnectStatus(token, deviceId, continuationManager.DeviceConnectState.CONNECTED, (err) => { 910e41f4b71Sopenharmony_ci if (err.code != 0) { 911e41f4b71Sopenharmony_ci console.error('updateConnectStatus failed, cause: ' + JSON.stringify(err)); 912e41f4b71Sopenharmony_ci return; 913e41f4b71Sopenharmony_ci } 914e41f4b71Sopenharmony_ci console.info('updateConnectStatus finished. '); 915e41f4b71Sopenharmony_ci }); 916e41f4b71Sopenharmony_ci ``` 917e41f4b71Sopenharmony_ci 918e41f4b71Sopenharmony_ci## continuationManager.updateConnectStatus<sup>(deprecated)</sup> 919e41f4b71Sopenharmony_ci 920e41f4b71Sopenharmony_ciupdateConnectStatus(token: number, deviceId: string, status: DeviceConnectState): Promise\<void> 921e41f4b71Sopenharmony_ci 922e41f4b71Sopenharmony_ci通知设备选择模块,更新当前的连接状态,使用Promise方式作为异步方法。 923e41f4b71Sopenharmony_ci 924e41f4b71Sopenharmony_ci> **说明:** 925e41f4b71Sopenharmony_ci> 926e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[updateContinuationState](#continuationmanagerupdatecontinuationstate9-1)替代。 927e41f4b71Sopenharmony_ci 928e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 929e41f4b71Sopenharmony_ci 930e41f4b71Sopenharmony_ci**参数:** 931e41f4b71Sopenharmony_ci 932e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 933e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 934e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 935e41f4b71Sopenharmony_ci | deviceId | string | 是 | 设备ID。 | 936e41f4b71Sopenharmony_ci | status | [DeviceConnectState](#deviceconnectstate) | 是 | 设备连接状态。 | 937e41f4b71Sopenharmony_ci 938e41f4b71Sopenharmony_ci**返回值:** 939e41f4b71Sopenharmony_ci 940e41f4b71Sopenharmony_ci| 类型 | 说明 | 941e41f4b71Sopenharmony_ci| ------------------------- | ------------------ | 942e41f4b71Sopenharmony_ci| Promise\<void> | Promise形式返回接口调用结果。 | 943e41f4b71Sopenharmony_ci 944e41f4b71Sopenharmony_ci**示例:** 945e41f4b71Sopenharmony_ci 946e41f4b71Sopenharmony_ci ```ts 947e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 948e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 949e41f4b71Sopenharmony_ci 950e41f4b71Sopenharmony_ci let token: number = 1; 951e41f4b71Sopenharmony_ci let deviceId: string = "test deviceId"; 952e41f4b71Sopenharmony_ci continuationManager.updateConnectStatus(token, deviceId, continuationManager.DeviceConnectState.CONNECTED) 953e41f4b71Sopenharmony_ci .then(() => { 954e41f4b71Sopenharmony_ci console.info('updateConnectStatus finished. '); 955e41f4b71Sopenharmony_ci }) 956e41f4b71Sopenharmony_ci .catch((err: BusinessError) => { 957e41f4b71Sopenharmony_ci console.error('updateConnectStatus failed, cause: ' + JSON.stringify(err)); 958e41f4b71Sopenharmony_ci }); 959e41f4b71Sopenharmony_ci ``` 960e41f4b71Sopenharmony_ci 961e41f4b71Sopenharmony_ci## continuationManager.updateContinuationState<sup>9+</sup> 962e41f4b71Sopenharmony_ci 963e41f4b71Sopenharmony_ciupdateContinuationState(token: number, deviceId: string, status: DeviceConnectState, callback: AsyncCallback\<void>): void 964e41f4b71Sopenharmony_ci 965e41f4b71Sopenharmony_ci通知设备选择模块,更新当前的连接状态,使用AsyncCallback方式作为异步方法。 966e41f4b71Sopenharmony_ci 967e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 968e41f4b71Sopenharmony_ci 969e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 970e41f4b71Sopenharmony_ci 971e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 972e41f4b71Sopenharmony_ci 973e41f4b71Sopenharmony_ci**参数:** 974e41f4b71Sopenharmony_ci 975e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 976e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 977e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 978e41f4b71Sopenharmony_ci | deviceId | string | 是 | 设备ID。 | 979e41f4b71Sopenharmony_ci | status | [DeviceConnectState](#deviceconnectstate) | 是 | 设备连接状态。 | 980e41f4b71Sopenharmony_ci | callback | AsyncCallback\<void> | 是 | 回调函数。当通知设备成功,err为undefined,否则返回错误对象。 | 981e41f4b71Sopenharmony_ci 982e41f4b71Sopenharmony_ci**错误码:** 983e41f4b71Sopenharmony_ci 984e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 985e41f4b71Sopenharmony_ci 986e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 987e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 988e41f4b71Sopenharmony_ci| 201 | Permission denied.| 989e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 990e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 991e41f4b71Sopenharmony_ci| 16600002 | The specified token or callback is not registered. | 992e41f4b71Sopenharmony_ci 993e41f4b71Sopenharmony_ci**示例:** 994e41f4b71Sopenharmony_ci 995e41f4b71Sopenharmony_ci ```ts 996e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 997e41f4b71Sopenharmony_ci 998e41f4b71Sopenharmony_ci let token: number = 1; 999e41f4b71Sopenharmony_ci let deviceId: string = "test deviceId"; 1000e41f4b71Sopenharmony_ci try { 1001e41f4b71Sopenharmony_ci continuationManager.updateContinuationState(token, deviceId, continuationManager.DeviceConnectState.CONNECTED, (err) => { 1002e41f4b71Sopenharmony_ci if (err.code != 0) { 1003e41f4b71Sopenharmony_ci console.error('updateContinuationState failed, cause: ' + JSON.stringify(err)); 1004e41f4b71Sopenharmony_ci return; 1005e41f4b71Sopenharmony_ci } 1006e41f4b71Sopenharmony_ci console.info('updateContinuationState finished. '); 1007e41f4b71Sopenharmony_ci }); 1008e41f4b71Sopenharmony_ci } catch (err) { 1009e41f4b71Sopenharmony_ci console.error('updateContinuationState failed, cause: ' + JSON.stringify(err)); 1010e41f4b71Sopenharmony_ci } 1011e41f4b71Sopenharmony_ci ``` 1012e41f4b71Sopenharmony_ci 1013e41f4b71Sopenharmony_ci## continuationManager.updateContinuationState<sup>9+</sup> 1014e41f4b71Sopenharmony_ci 1015e41f4b71Sopenharmony_ciupdateContinuationState(token: number, deviceId: string, status: DeviceConnectState): Promise\<void> 1016e41f4b71Sopenharmony_ci 1017e41f4b71Sopenharmony_ci通知设备选择模块,更新当前的连接状态,使用Promise方式作为异步方法。 1018e41f4b71Sopenharmony_ci 1019e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1020e41f4b71Sopenharmony_ci 1021e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 1022e41f4b71Sopenharmony_ci 1023e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 1024e41f4b71Sopenharmony_ci 1025e41f4b71Sopenharmony_ci**参数:** 1026e41f4b71Sopenharmony_ci 1027e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 1028e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 1029e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 1030e41f4b71Sopenharmony_ci | deviceId | string | 是 | 设备ID。 | 1031e41f4b71Sopenharmony_ci | status | [DeviceConnectState](#deviceconnectstate) | 是 | 设备连接状态。 | 1032e41f4b71Sopenharmony_ci 1033e41f4b71Sopenharmony_ci**返回值:** 1034e41f4b71Sopenharmony_ci 1035e41f4b71Sopenharmony_ci| 类型 | 说明 | 1036e41f4b71Sopenharmony_ci| ------------------------- | ------------------ | 1037e41f4b71Sopenharmony_ci| Promise\<void> | Promise形式返回接口调用结果。 | 1038e41f4b71Sopenharmony_ci 1039e41f4b71Sopenharmony_ci**错误码:** 1040e41f4b71Sopenharmony_ci 1041e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 1042e41f4b71Sopenharmony_ci 1043e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1044e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 1045e41f4b71Sopenharmony_ci| 201 | Permission denied.| 1046e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1047e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 1048e41f4b71Sopenharmony_ci| 16600002 | The specified token or callback is not registered. | 1049e41f4b71Sopenharmony_ci 1050e41f4b71Sopenharmony_ci**示例:** 1051e41f4b71Sopenharmony_ci 1052e41f4b71Sopenharmony_ci ```ts 1053e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 1054e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 1055e41f4b71Sopenharmony_ci 1056e41f4b71Sopenharmony_ci let token: number = 1; 1057e41f4b71Sopenharmony_ci let deviceId: string = "test deviceId"; 1058e41f4b71Sopenharmony_ci try { 1059e41f4b71Sopenharmony_ci continuationManager.updateContinuationState(token, deviceId, continuationManager.DeviceConnectState.CONNECTED) 1060e41f4b71Sopenharmony_ci .then(() => { 1061e41f4b71Sopenharmony_ci console.info('updateContinuationState finished. '); 1062e41f4b71Sopenharmony_ci }) 1063e41f4b71Sopenharmony_ci .catch((err: BusinessError) => { 1064e41f4b71Sopenharmony_ci console.error('updateContinuationState failed, cause: ' + JSON.stringify(err)); 1065e41f4b71Sopenharmony_ci }); 1066e41f4b71Sopenharmony_ci } catch (err) { 1067e41f4b71Sopenharmony_ci console.error('updateContinuationState failed, cause: ' + JSON.stringify(err)); 1068e41f4b71Sopenharmony_ci } 1069e41f4b71Sopenharmony_ci ``` 1070e41f4b71Sopenharmony_ci 1071e41f4b71Sopenharmony_ci 1072e41f4b71Sopenharmony_ci## continuationManager.unregister<sup>(deprecated)</sup> 1073e41f4b71Sopenharmony_ci 1074e41f4b71Sopenharmony_ciunregister(token: number, callback: AsyncCallback\<void>): void 1075e41f4b71Sopenharmony_ci 1076e41f4b71Sopenharmony_ci解注册流转管理服务,传入注册时获取的token进行解注册,使用AsyncCallback方式作为异步方法。 1077e41f4b71Sopenharmony_ci 1078e41f4b71Sopenharmony_ci> **说明:** 1079e41f4b71Sopenharmony_ci> 1080e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[unregisterContinuation](#continuationmanagerunregistercontinuation9)替代。 1081e41f4b71Sopenharmony_ci 1082e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 1083e41f4b71Sopenharmony_ci 1084e41f4b71Sopenharmony_ci**参数:** 1085e41f4b71Sopenharmony_ci 1086e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 1087e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 1088e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 1089e41f4b71Sopenharmony_ci | callback | AsyncCallback\<void> | 是 | 回调函数。当解注册成功,err为undefined,否则返回错误对象。 | 1090e41f4b71Sopenharmony_ci 1091e41f4b71Sopenharmony_ci**示例:** 1092e41f4b71Sopenharmony_ci 1093e41f4b71Sopenharmony_ci ```ts 1094e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 1095e41f4b71Sopenharmony_ci 1096e41f4b71Sopenharmony_ci let token: number = 1; 1097e41f4b71Sopenharmony_ci continuationManager.unregister(token, (err) => { 1098e41f4b71Sopenharmony_ci if (err.code != 0) { 1099e41f4b71Sopenharmony_ci console.error('unregister failed, cause: ' + JSON.stringify(err)); 1100e41f4b71Sopenharmony_ci return; 1101e41f4b71Sopenharmony_ci } 1102e41f4b71Sopenharmony_ci console.info('unregister finished. '); 1103e41f4b71Sopenharmony_ci }); 1104e41f4b71Sopenharmony_ci ``` 1105e41f4b71Sopenharmony_ci 1106e41f4b71Sopenharmony_ci## continuationManager.unregister<sup>(deprecated)</sup> 1107e41f4b71Sopenharmony_ci 1108e41f4b71Sopenharmony_ciunregister(token: number): Promise\<void> 1109e41f4b71Sopenharmony_ci 1110e41f4b71Sopenharmony_ci解注册流转管理服务,传入注册时获取的token进行解注册,使用Promise方式作为异步方法。 1111e41f4b71Sopenharmony_ci 1112e41f4b71Sopenharmony_ci> **说明:** 1113e41f4b71Sopenharmony_ci> 1114e41f4b71Sopenharmony_ci> 从API version 9开始不再维护,建议使用[unregisterContinuation](#continuationmanagerunregistercontinuation9-1)替代。 1115e41f4b71Sopenharmony_ci 1116e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 1117e41f4b71Sopenharmony_ci 1118e41f4b71Sopenharmony_ci**参数:** 1119e41f4b71Sopenharmony_ci 1120e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 1121e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 1122e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 1123e41f4b71Sopenharmony_ci 1124e41f4b71Sopenharmony_ci**返回值:** 1125e41f4b71Sopenharmony_ci 1126e41f4b71Sopenharmony_ci| 类型 | 说明 | 1127e41f4b71Sopenharmony_ci| ------------------------- | ------------------ | 1128e41f4b71Sopenharmony_ci| Promise\<void> | Promise形式返回接口调用结果。 | 1129e41f4b71Sopenharmony_ci 1130e41f4b71Sopenharmony_ci**示例:** 1131e41f4b71Sopenharmony_ci 1132e41f4b71Sopenharmony_ci ```ts 1133e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 1134e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 1135e41f4b71Sopenharmony_ci 1136e41f4b71Sopenharmony_ci let token: number = 1; 1137e41f4b71Sopenharmony_ci continuationManager.unregister(token) 1138e41f4b71Sopenharmony_ci .then(() => { 1139e41f4b71Sopenharmony_ci console.info('unregister finished. '); 1140e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1141e41f4b71Sopenharmony_ci console.error('unregister failed, cause: ' + JSON.stringify(err)); 1142e41f4b71Sopenharmony_ci }); 1143e41f4b71Sopenharmony_ci ``` 1144e41f4b71Sopenharmony_ci 1145e41f4b71Sopenharmony_ci## continuationManager.unregisterContinuation<sup>9+</sup> 1146e41f4b71Sopenharmony_ci 1147e41f4b71Sopenharmony_ciunregisterContinuation(token: number, callback: AsyncCallback\<void>): void 1148e41f4b71Sopenharmony_ci 1149e41f4b71Sopenharmony_ci解注册流转管理服务,传入注册时获取的token进行解注册,使用AsyncCallback方式作为异步方法。 1150e41f4b71Sopenharmony_ci 1151e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1152e41f4b71Sopenharmony_ci 1153e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 1154e41f4b71Sopenharmony_ci 1155e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 1156e41f4b71Sopenharmony_ci 1157e41f4b71Sopenharmony_ci**参数:** 1158e41f4b71Sopenharmony_ci 1159e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 1160e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 1161e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 1162e41f4b71Sopenharmony_ci | callback | AsyncCallback\<void> | 是 | 回调函数。当解注册成功,err为undefined,否则返回错误对象。 | 1163e41f4b71Sopenharmony_ci 1164e41f4b71Sopenharmony_ci**错误码:** 1165e41f4b71Sopenharmony_ci 1166e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 1167e41f4b71Sopenharmony_ci 1168e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1169e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 1170e41f4b71Sopenharmony_ci| 201 | Permission denied.| 1171e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1172e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 1173e41f4b71Sopenharmony_ci| 16600002 | The specified token or callback is not registered. | 1174e41f4b71Sopenharmony_ci 1175e41f4b71Sopenharmony_ci**示例:** 1176e41f4b71Sopenharmony_ci 1177e41f4b71Sopenharmony_ci ```ts 1178e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 1179e41f4b71Sopenharmony_ci 1180e41f4b71Sopenharmony_ci let token: number = 1; 1181e41f4b71Sopenharmony_ci try { 1182e41f4b71Sopenharmony_ci continuationManager.unregisterContinuation(token, (err) => { 1183e41f4b71Sopenharmony_ci if (err.code != 0) { 1184e41f4b71Sopenharmony_ci console.error('unregisterContinuation failed, cause: ' + JSON.stringify(err)); 1185e41f4b71Sopenharmony_ci return; 1186e41f4b71Sopenharmony_ci } 1187e41f4b71Sopenharmony_ci console.info('unregisterContinuation finished. '); 1188e41f4b71Sopenharmony_ci }); 1189e41f4b71Sopenharmony_ci } catch (err) { 1190e41f4b71Sopenharmony_ci console.error('unregisterContinuation failed, cause: ' + JSON.stringify(err)); 1191e41f4b71Sopenharmony_ci } 1192e41f4b71Sopenharmony_ci ``` 1193e41f4b71Sopenharmony_ci 1194e41f4b71Sopenharmony_ci## continuationManager.unregisterContinuation<sup>9+</sup> 1195e41f4b71Sopenharmony_ci 1196e41f4b71Sopenharmony_ciunregisterContinuation(token: number): Promise\<void> 1197e41f4b71Sopenharmony_ci 1198e41f4b71Sopenharmony_ci解注册流转管理服务,传入注册时获取的token进行解注册,使用Promise方式作为异步方法。 1199e41f4b71Sopenharmony_ci 1200e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1201e41f4b71Sopenharmony_ci 1202e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 1203e41f4b71Sopenharmony_ci 1204e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 1205e41f4b71Sopenharmony_ci 1206e41f4b71Sopenharmony_ci**参数:** 1207e41f4b71Sopenharmony_ci 1208e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 1209e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 1210e41f4b71Sopenharmony_ci | token | number | 是 | 注册后的token。 | 1211e41f4b71Sopenharmony_ci 1212e41f4b71Sopenharmony_ci**返回值:** 1213e41f4b71Sopenharmony_ci 1214e41f4b71Sopenharmony_ci| 类型 | 说明 | 1215e41f4b71Sopenharmony_ci| ------------------------- | ------------------ | 1216e41f4b71Sopenharmony_ci| Promise\<void> | Promise形式返回接口调用结果。 | 1217e41f4b71Sopenharmony_ci 1218e41f4b71Sopenharmony_ci**错误码:** 1219e41f4b71Sopenharmony_ci 1220e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[分布式调度错误码](errorcode-DistributedSchedule.md)。 1221e41f4b71Sopenharmony_ci 1222e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1223e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 1224e41f4b71Sopenharmony_ci| 201 | Permission denied.| 1225e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1226e41f4b71Sopenharmony_ci| 16600001 | The system ability works abnormally. | 1227e41f4b71Sopenharmony_ci| 16600002 | The specified token or callback is not registered. | 1228e41f4b71Sopenharmony_ci 1229e41f4b71Sopenharmony_ci**示例:** 1230e41f4b71Sopenharmony_ci 1231e41f4b71Sopenharmony_ci ```ts 1232e41f4b71Sopenharmony_ci import { continuationManager } from '@kit.AbilityKit'; 1233e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 1234e41f4b71Sopenharmony_ci 1235e41f4b71Sopenharmony_ci let token: number = -1; 1236e41f4b71Sopenharmony_ci try { 1237e41f4b71Sopenharmony_ci continuationManager.unregisterContinuation(token).then(() => { 1238e41f4b71Sopenharmony_ci console.info('unregisterContinuation finished. '); 1239e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1240e41f4b71Sopenharmony_ci console.error('unregisterContinuation failed, cause: ' + JSON.stringify(err)); 1241e41f4b71Sopenharmony_ci }); 1242e41f4b71Sopenharmony_ci } catch (err) { 1243e41f4b71Sopenharmony_ci console.error('unregisterContinuation failed, cause: ' + JSON.stringify(err)); 1244e41f4b71Sopenharmony_ci } 1245e41f4b71Sopenharmony_ci ``` 1246e41f4b71Sopenharmony_ci 1247e41f4b71Sopenharmony_ci 1248e41f4b71Sopenharmony_ci## DeviceConnectState 1249e41f4b71Sopenharmony_ci 1250e41f4b71Sopenharmony_ci设备连接状态。 1251e41f4b71Sopenharmony_ci 1252e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1253e41f4b71Sopenharmony_ci 1254e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 1255e41f4b71Sopenharmony_ci 1256e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 1257e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 1258e41f4b71Sopenharmony_ci| IDLE | 0 | 设备连接初始状态。 | 1259e41f4b71Sopenharmony_ci| CONNECTING | 1 | 设备连接中状态。 | 1260e41f4b71Sopenharmony_ci| CONNECTED | 2 | 设备已连接状态。 | 1261e41f4b71Sopenharmony_ci| DISCONNECTING | 3 | 设备断开连接状态。 | 1262e41f4b71Sopenharmony_ci 1263e41f4b71Sopenharmony_ci## ContinuationMode 1264e41f4b71Sopenharmony_ci 1265e41f4b71Sopenharmony_ci设备选择模块连接模式。 1266e41f4b71Sopenharmony_ci 1267e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1268e41f4b71Sopenharmony_ci 1269e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.DistributedAbilityManager 1270e41f4b71Sopenharmony_ci 1271e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 1272e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 1273e41f4b71Sopenharmony_ci| COLLABORATION_SINGLE | 0 | 设备选择模块单选模式。 | 1274e41f4b71Sopenharmony_ci| COLLABORATION_MULTIPLE | 1 | 设备选择模块多选模式。 |