鸿蒙OpenHarmony【@ohos.enterprise.networkManager(网络管理)】ArkTS API

本模块提供设备网络管理能力,包括查询设备IP地址、MAC地址信息等。

说明

本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

本模块接口仅可在Stage模型下使用。

本模块接口仅对[设备管理应用]开放,需将设备管理应用激活后调用,实现相应功能。

导入模块

import { networkManager } from '@kit.MDMKit';

networkManager.getAllNetworkInterfacesSync

getAllNetworkInterfacesSync(admin: Want): Array

指定设备管理应用获取所有激活的网络接口。

需要权限:  ohos.permission.ENTERPRISE_MANAGE_NETWORK

系统能力:  SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin [Want] 设备管理应用。

返回值:

类型 说明
Array 返回网络接口名称数组。
错误码ID 错误信息
9200001 The application is not an administrator application of the device.
9200002 The administrator application does not have permission to manage the device.
201 Permission verification failed. The application does not have the permission required to call the API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

示例:

import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

try {
  let result: Array<string> = networkManager.getAllNetworkInterfacesSync(wantTemp);
  console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`);
} catch (err) {
  console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`);
}

networkManager.getIpAddressSync

getIpAddressSync(admin: Want, networkInterface: string): string

指定设备管理应用根据网络接口获取设备IP地址。

需要权限:  ohos.permission.ENTERPRISE_MANAGE_NETWORK

系统能力:  SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin [Want] 设备管理应用。
networkInterface string 指定网络接口。

返回值:

类型 说明
string 返回设备IP地址。
错误码ID 错误信息
9200001 The application is not an administrator application of the device.
9200002 The administrator application does not have permission to manage the device.
201 Permission verification failed. The application does not have the permission required to call the API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

示例:

import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

try {
  let result: string = networkManager.getIpAddressSync(wantTemp, 'eth0');
  console.info(`Succeeded in getting ip address, result : ${result}`);
} catch (err) {
  console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`);
}

networkManager.getMacSync

getMacSync(admin: Want, networkInterface: string): string

指定设备管理应用根据网络接口获取设备MAC地址。

需要权限:  ohos.permission.ENTERPRISE_MANAGE_NETWORK

系统能力:  SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin [Want] 设备管理应用。
networkInterface string 指定网络接口。

返回值:

类型 说明
string 返回设备MAC地址。
错误码ID 错误信息
9200001 The application is not an administrator application of the device.
9200002 The administrator application does not have permission to manage the device.
201 Permission verification failed. The application does not have the permission required to call the API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

示例:

import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

try {
  let result: str
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值