OpenHarmony开发者论坛

标题: 请教一下通过什么方式可以调用@ohos.wifiManager被隐藏的wifiManager.getDeviceMacAddress()函数来获取MAC地址 [打印本页]

作者: sonia    时间: 2025-4-9 15:05
标题: 请教一下通过什么方式可以调用@ohos.wifiManager被隐藏的wifiManager.getDeviceMacAddress()函数来获取MAC地址
[md]如题:请教一下专家,

通过什么方式可以调用@ohos.wifiManager被隐藏的wifiManager.getDeviceMacAddress()函数来获取MAC地址;

C:\\Program Files\\Huawei\\DevEcoStudio507\\sdk\\default\\openharmony\\ets\\api\\@ohos.wifimanager.d.ts里getDeviceMacAddress()函数被隐藏了,

![](https://i-blog.csdnimg.cn/devpre ... 6b0e6175ed795bb.png)

但是框架层是支持这个函数的,在interface/sdk-js/api/@ohos.wifimanager.d.ts里有该函数的定义,但是拷贝替换过去以后,dev-eco仍然不识别;提示以下编译错误:

有什么步骤操作能使用到这个函数或其它正规途径来获取OpenHarmony5.0下的WiFi MAC啊?

![保存mac.png](https://forums-obs.openharmony.c ... hxrc3e9lvxzm8lh.png "保存mac.png")
[/md]
作者: onefan    时间: 2025-4-9 16:22
1.你这是any类型

要改一下

let mac: string[] = wifiManager.getDeviceMacAddress();
2.

import wifiManager from '@ohos.wifiManager';
在@ohos.wifiManager中有getDeviceMacAddress不?需要full's'd'k

/**
* Obtain the MAC address of a Wi-Fi device. Wi-Fi must be enabled.
* The MAC address is unique and cannot be changed.
* @permission ohos.permission.GET_WIFI_LOCAL_MAC and ohos.permission.GET_WIFI_INFO
* @returns { string[] } Returns the MAC address of the Wi-Fi device.
* @throws {BusinessError} 201 - Permission denied.
* @throws {BusinessError} 202 - System API is not allowed called by Non-system application.
* @throws {BusinessError} 801 - Capability not supported.
* @throws {BusinessError} 2501000 - Operation failed.
* @throws {BusinessError} 2501001 - Wifi is closed.
* @syscap SystemCapability.Communication.WiFi.STA
* @systemapi Hide this for inner system use.
* @since 9
*/
function getDeviceMacAddress(): string[];




欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/) Powered by Discuz! X3.5