如何以编程方式在Android 9中找到已连接的WiFi Macaddress?

发布于 2025-01-25 13:01:01 字数 541 浏览 4 评论 0原文

android文档

Mac地址在全球范围内是独一无二的,不可用户候选人,并且可以生存 工厂重置。由于这些原因,保护用户隐私,在Android上 版本6及更高版本,访问MAC地址仅限于系统 应用。第三方应用无法访问它们

,但是此 app 在Play商店中显示WiFi Macaddress。

我正在研究一个项目,该项目涉及找到连接的WiFi MAC地址,并且我尝试了几乎所有在Stackoverflow上可用的解决方案,但它们都无法正常工作。

如果上述应用程序可以访问WiFi MAC地址,那么我们也可以如何?

Android documentation reference

MAC addresses are globally unique, not user-resettable, and survive
factory resets. For these reasons, to protect user privacy, on Android
versions 6 and higher, access to MAC addresses is restricted to system
apps. Third-party apps can't access them

But this app on the play store shows the Wifi MacAddress.

I'm working on a project which involves the finding of connected WIFI Mac addresses and I've tried almost every solution available on StackOverflow but none of them is working.

If the above mention app can access the wifi mac address then we can too but how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愛放△進行李 2025-02-01 13:01:01

我正在使用Android 10,并在下面使用此代码:

fun getMacAddress(): String {
    try {
        val all: List<NetworkInterface> = Collections.list(NetworkInterface.getNetworkInterfaces())
        for (networkInterface in all) {
            if (!networkInterface.name.equals("wlan0", true)) continue
            val macBytes = networkInterface.hardwareAddress ?: return ""
            val res1 = StringBuilder()
            for (b in macBytes) {
                res1.append(String.format("%02X:", b))
            }
            if (res1.isNotEmpty()) {
                res1.deleteCharAt(res1.length - 1)
            }
            return res1.toString()
        }
    } catch (ex: java.lang.Exception) {
        Log.e("TAG", "getMacAddress: ", ex)
    }
    return ""
}

希望这对您有帮助!

I'm using Android 10 and i use this code below :

fun getMacAddress(): String {
    try {
        val all: List<NetworkInterface> = Collections.list(NetworkInterface.getNetworkInterfaces())
        for (networkInterface in all) {
            if (!networkInterface.name.equals("wlan0", true)) continue
            val macBytes = networkInterface.hardwareAddress ?: return ""
            val res1 = StringBuilder()
            for (b in macBytes) {
                res1.append(String.format("%02X:", b))
            }
            if (res1.isNotEmpty()) {
                res1.deleteCharAt(res1.length - 1)
            }
            return res1.toString()
        }
    } catch (ex: java.lang.Exception) {
        Log.e("TAG", "getMacAddress: ", ex)
    }
    return ""
}

I hope this will help you !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文