gpt4 book ai didi

java - 以编程方式获取 Android 设备的 MAC

转载 作者:IT老高 更新时间:2023-10-28 11:45:21 28 4
gpt4 key购买 nike

我需要使用 Java 获取我的 android 设备的 MAC 地址。我在网上搜索过,但没有找到任何有用的东西。

最佳答案

正如评论中已经指出的那样,可以通过 WifiManager 接收 MAC 地址。 .

WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = manager.getConnectionInfo();
String address = info.getMacAddress();

另外不要忘记将适当的权限添加到您的 AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

请引用Android 6.0 Changes .

To provide users with greater data protection, starting in this release, Android removes programmatic access to the device’s local hardware identifier for apps using the Wi-Fi and Bluetooth APIs. The WifiInfo.getMacAddress() and the BluetoothAdapter.getAddress() methods now return a constant value of 02:00:00:00:00:00.

To access the hardware identifiers of nearby external devices via Bluetooth and Wi-Fi scans, your app must now have the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions.

关于java - 以编程方式获取 Android 设备的 MAC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11705906/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com