1e41f4b71Sopenharmony_ci# @ohos.net.connection (网络连接管理)(系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci网络连接管理提供管理网络一些基础能力,包括获取默认激活的数据网络、获取所有激活数据网络列表、开启关闭飞行模式、获取网络能力信息等功能。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 7e41f4b71Sopenharmony_ci> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.net.connection (网络连接管理)](js-apis-net-connection.md) 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## 导入模块 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci```ts 12e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit'; 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## connection.getGlobalHttpProxy<sup>10+</sup> 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_cigetGlobalHttpProxy(callback: AsyncCallback\<HttpProxy>): void 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci获取网络的全局代理配置信息,使用callback方式作为异步方法。 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.NetManager.Core 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci**参数:** 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 29e41f4b71Sopenharmony_ci| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 30e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[HttpProxy](js-apis-net-connection.md#httpproxy10)> | 是 | 回调函数。当成功获取网络的全局代理配置信息时,error为undefined,data为网络的全局代理配置信息;否则为错误对象 | 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**错误码:** 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 35e41f4b71Sopenharmony_ci| ------- | ----------------------------- | 36e41f4b71Sopenharmony_ci| 401 | Parameter error. | 37e41f4b71Sopenharmony_ci| 202 | Non-system applications use system APIs. | 38e41f4b71Sopenharmony_ci| 2100002 | Failed to connect to the service.| 39e41f4b71Sopenharmony_ci| 2100003 | System internal error. | 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**示例:** 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci```ts 44e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit'; 45e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ciconnection.getGlobalHttpProxy((error: BusinessError, data: connection.HttpProxy) => { 48e41f4b71Sopenharmony_ci console.info(JSON.stringify(error)); 49e41f4b71Sopenharmony_ci console.info(JSON.stringify(data)); 50e41f4b71Sopenharmony_ci}); 51e41f4b71Sopenharmony_ci``` 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci## connection.getGlobalHttpProxy<sup>10+</sup> 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_cigetGlobalHttpProxy(): Promise\<HttpProxy>; 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci获取网络的全局代理配置信息,使用Promise方式作为异步方法。 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.NetManager.Core 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci**返回值:** 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci| 类型 | 说明 | 66e41f4b71Sopenharmony_ci| --------------------------------- | ------------------------------------- | 67e41f4b71Sopenharmony_ci| Promise\<[HttpProxy](js-apis-net-connection.md#httpproxy10)> | 以Promise形式返回网络的全局代理配置信息。 | 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci**错误码:** 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 72e41f4b71Sopenharmony_ci| ------- | ----------------------------- | 73e41f4b71Sopenharmony_ci| 202 | Non-system applications use system APIs. | 74e41f4b71Sopenharmony_ci| 2100002 | Failed to connect to the service.| 75e41f4b71Sopenharmony_ci| 2100003 | System internal error. | 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci**示例:** 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci```ts 80e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit'; 81e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ciconnection.getGlobalHttpProxy().then((data: connection.HttpProxy) => { 84e41f4b71Sopenharmony_ci console.info(JSON.stringify(data)); 85e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 86e41f4b71Sopenharmony_ci console.info(JSON.stringify(error)); 87e41f4b71Sopenharmony_ci}); 88e41f4b71Sopenharmony_ci``` 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci## connection.setGlobalHttpProxy<sup>10+</sup> 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_cisetGlobalHttpProxy(httpProxy: HttpProxy, callback: AsyncCallback\<void>): void 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci设置网络全局Http代理配置信息,使用callback方式作为异步方法。 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.NetManager.Core 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**参数:** 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 105e41f4b71Sopenharmony_ci| --------- | ----------------------- | ---- | ------------------------------------------------------------ | 106e41f4b71Sopenharmony_ci| httpProxy | [HttpProxy](js-apis-net-connection.md#httpproxy10) | 是 | 网络全局Http代理配置信息。 | 107e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | 是 | 回调函数。当成功设置网络全局Http代理配置信息时,error为undefined,否则为错误对象。| 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci**错误码:** 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 112e41f4b71Sopenharmony_ci| ------- | ----------------------------- | 113e41f4b71Sopenharmony_ci| 201 | Permission denied. | 114e41f4b71Sopenharmony_ci| 401 | Parameter error. | 115e41f4b71Sopenharmony_ci| 202 | Non-system applications use system APIs. | 116e41f4b71Sopenharmony_ci| 2100001 | Invalid parameter value. | 117e41f4b71Sopenharmony_ci| 2100002 | Failed to connect to the service.| 118e41f4b71Sopenharmony_ci| 2100003 | System internal error. | 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci**示例:** 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci```ts 123e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit'; 124e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_cilet exclusionStr = "192.168,baidu.com"; 127e41f4b71Sopenharmony_cilet exclusionArray = exclusionStr.split(','); 128e41f4b71Sopenharmony_cilet httpProxy: connection.HttpProxy = { 129e41f4b71Sopenharmony_ci host: "192.168.xx.xxx", 130e41f4b71Sopenharmony_ci port: 8080, 131e41f4b71Sopenharmony_ci exclusionList: exclusionArray 132e41f4b71Sopenharmony_ci} 133e41f4b71Sopenharmony_ciconnection.setGlobalHttpProxy(httpProxy, (err: BusinessError) => { 134e41f4b71Sopenharmony_ci if (err) { 135e41f4b71Sopenharmony_ci console.error(`setGlobalHttpProxy failed, callback: err->${JSON.stringify(err)}`); 136e41f4b71Sopenharmony_ci return; 137e41f4b71Sopenharmony_ci } 138e41f4b71Sopenharmony_ci console.log(`setGlobalHttpProxy success.`); 139e41f4b71Sopenharmony_ci}); 140e41f4b71Sopenharmony_ci``` 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci## connection.setGlobalHttpProxy<sup>10+</sup> 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_cisetGlobalHttpProxy(httpProxy: HttpProxy): Promise\<void>; 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci设置网络全局Http代理配置信息,使用Promise方式作为异步方法。 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.NetManager.Core 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci**参数:** 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 157e41f4b71Sopenharmony_ci| --------- | ------------------------------------------------------------ | ---- | ---------------- | 158e41f4b71Sopenharmony_ci| httpProxy | [HttpProxy](js-apis-net-connection.md#httpproxy10) | 是 | 网络全局Http代理配置信息。 | 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci**返回值:** 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci| 类型 | 说明 | 163e41f4b71Sopenharmony_ci| ------------------------------------------- | ----------------------------- | 164e41f4b71Sopenharmony_ci| Promise\<void> | 无返回值的Promise对象。 | 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci**错误码:** 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 169e41f4b71Sopenharmony_ci| ------- | ----------------------------- | 170e41f4b71Sopenharmony_ci| 201 | Permission denied. | 171e41f4b71Sopenharmony_ci| 401 | Parameter error. | 172e41f4b71Sopenharmony_ci| 202 | Non-system applications use system APIs. | 173e41f4b71Sopenharmony_ci| 2100001 | Invalid parameter value. | 174e41f4b71Sopenharmony_ci| 2100002 | Failed to connect to the service.| 175e41f4b71Sopenharmony_ci| 2100003 | System internal error. | 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci**示例:** 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci```ts 180e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit'; 181e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_cilet exclusionStr = "192.168,baidu.com"; 184e41f4b71Sopenharmony_cilet exclusionArray = exclusionStr.split(','); 185e41f4b71Sopenharmony_ciconnection.setGlobalHttpProxy({ 186e41f4b71Sopenharmony_ci host: "192.168.xx.xxx", 187e41f4b71Sopenharmony_ci port: 8080, 188e41f4b71Sopenharmony_ci exclusionList: exclusionArray 189e41f4b71Sopenharmony_ci} as connection.HttpProxy).then(() => { 190e41f4b71Sopenharmony_ci console.info("success"); 191e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 192e41f4b71Sopenharmony_ci console.info(JSON.stringify(error)); 193e41f4b71Sopenharmony_ci}); 194e41f4b71Sopenharmony_ci``` 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci## connection.enableAirplaneMode 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_cienableAirplaneMode(callback: AsyncCallback\<void>): void 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci开启飞行模式,使用callback方式作为异步方法。 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.NetManager.Core 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci**参数:** 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 212e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- | ---- | ------------------ | 213e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | 是 | 回调函数。 | 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci**错误码:** 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 218e41f4b71Sopenharmony_ci| ------- | ----------------------------- | 219e41f4b71Sopenharmony_ci| 201 | Permission denied. | 220e41f4b71Sopenharmony_ci| 202 | Non-system applications use system APIs. | 221e41f4b71Sopenharmony_ci| 401 | Parameter error. | 222e41f4b71Sopenharmony_ci| 2100002 | Failed to connect to the service.| 223e41f4b71Sopenharmony_ci| 2100003 | System internal error. | 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci**示例:** 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci```ts 228e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit'; 229e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ciconnection.enableAirplaneMode((error: BusinessError) => { 232e41f4b71Sopenharmony_ci console.log(JSON.stringify(error)); 233e41f4b71Sopenharmony_ci}); 234e41f4b71Sopenharmony_ci``` 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci## connection.enableAirplaneMode 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_cienableAirplaneMode(): Promise\<void> 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci开启飞行模式,使用Promise方式作为异步方法。 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.NetManager.Core 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci**返回值:** 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci| 类型 | 说明 | 251e41f4b71Sopenharmony_ci| ------------------------------------------- | ----------------------------- | 252e41f4b71Sopenharmony_ci| Promise\<void> | 无返回值的Promise对象。 | 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci**错误码:** 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 257e41f4b71Sopenharmony_ci| ------- | ----------------------------- | 258e41f4b71Sopenharmony_ci| 201 | Permission denied. | 259e41f4b71Sopenharmony_ci| 202 | Non-system applications use system APIs. | 260e41f4b71Sopenharmony_ci| 2100002 | Failed to connect to the service.| 261e41f4b71Sopenharmony_ci| 2100003 | System internal error. | 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci**示例:** 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci```ts 266e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit'; 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ciconnection.enableAirplaneMode().then((error: void) => { 269e41f4b71Sopenharmony_ci console.log(JSON.stringify(error)); 270e41f4b71Sopenharmony_ci}); 271e41f4b71Sopenharmony_ci``` 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ci## connection.disableAirplaneMode 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_cidisableAirplaneMode(callback: AsyncCallback\<void>): void 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci关闭飞行模式,使用callback方式作为异步方法。 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.NetManager.Core 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci**参数:** 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 288e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- | ---- | ------------------ | 289e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | 是 | 回调函数。当关闭飞行模式成功,error为undefined,否则为错误对象。 | 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ci**错误码:** 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 294e41f4b71Sopenharmony_ci| ------- | ----------------------------- | 295e41f4b71Sopenharmony_ci| 201 | Permission denied. | 296e41f4b71Sopenharmony_ci| 202 | Non-system applications use system APIs. | 297e41f4b71Sopenharmony_ci| 401 | Parameter error. | 298e41f4b71Sopenharmony_ci| 2100002 | Failed to connect to the service.| 299e41f4b71Sopenharmony_ci| 2100003 | System internal error. | 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_ci**示例:** 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci```ts 304e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit'; 305e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ciconnection.disableAirplaneMode((error: BusinessError) => { 308e41f4b71Sopenharmony_ci console.log(JSON.stringify(error)); 309e41f4b71Sopenharmony_ci}); 310e41f4b71Sopenharmony_ci``` 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci## connection.disableAirplaneMode 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_cidisableAirplaneMode(): Promise\<void> 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci关闭飞行模式,使用Promise方式作为异步方法。 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.NetManager.Core 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci**返回值:** 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci| 类型 | 说明 | 327e41f4b71Sopenharmony_ci| ------------------------------------------- | ----------------------------- | 328e41f4b71Sopenharmony_ci| Promise\<void> | 无返回值的Promise对象。 | 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci**错误码:** 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 333e41f4b71Sopenharmony_ci| ------- | ----------------------------- | 334e41f4b71Sopenharmony_ci| 201 | Permission denied. | 335e41f4b71Sopenharmony_ci| 202 | Non-system applications use system APIs. | 336e41f4b71Sopenharmony_ci| 2100002 | Failed to connect to the service.| 337e41f4b71Sopenharmony_ci| 2100003 | System internal error. | 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci**示例:** 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci```ts 342e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit'; 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ciconnection.disableAirplaneMode().then((error: void) => { 345e41f4b71Sopenharmony_ci console.log(JSON.stringify(error)); 346e41f4b71Sopenharmony_ci}); 347e41f4b71Sopenharmony_ci``` 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci## connection.factoryReset<sup>11+</sup> 351e41f4b71Sopenharmony_ci 352e41f4b71Sopenharmony_cifactoryReset(): Promise\<void\> 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci出厂重置网络设置,使用Promise方式作为异步方法。 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.NetManager.Core 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci**返回值:** 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci| 类型 | 说明 | 365e41f4b71Sopenharmony_ci| ---------------------- | ----------------------- | 366e41f4b71Sopenharmony_ci| Promise\<void\> | 无返回值的Promise对象。 | 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci**错误码:** 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 371e41f4b71Sopenharmony_ci| ------- | ------------------------------------------ | 372e41f4b71Sopenharmony_ci| 201 | Permission denied. | 373e41f4b71Sopenharmony_ci| 202 | Non-system applications use system APIs. | 374e41f4b71Sopenharmony_ci| 2100002 | Failed to connect to the service.| 375e41f4b71Sopenharmony_ci| 2100003 | System internal error. | 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci**示例:** 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci```ts 380e41f4b71Sopenharmony_ciimport { connection } from '@kit.NetworkKit'; 381e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ciconnection.factoryReset().then(() => { 384e41f4b71Sopenharmony_ci console.log("success"); 385e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 386e41f4b71Sopenharmony_ci console.log(JSON.stringify(error)); 387e41f4b71Sopenharmony_ci}) 388e41f4b71Sopenharmony_ci```