如何以编程方式查找Android设备的MAC地址 [英] How to find MAC address of an Android device programmatically
问题描述
如何以编程方式获取android设备的Mac ID.我已经完成了IMIE Code,并且知道如何手动检查设备上的Mac ID,但不知道如何以编程方式查找.
How do i get Mac Id of android device programmatically. I have done with IMIE Code and I know how to check Mac id on device manually but have no idea how to find out programmatically.
推荐答案
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String macAddress = wInfo.getMacAddress();
此外,在清单文件中添加以下权限
Also, add below permission in your manifest file
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
请参考 Android 6.0的更改.
为了向用户提供更大的数据保护,从此版本开始,Android删除了使用Wi-Fi和Bluetooth API对应用的设备本地硬件标识符的编程访问. WifiInfo.getMacAddress()和BluetoothAdapter.getAddress()方法现在返回常数值02:00:00:00:00:00.
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.
要通过蓝牙和Wi-Fi扫描访问附近的外部设备的硬件标识符,您的应用现在必须具有ACCESS_FINE_LOCATION或ACCESS_COARSE_LOCATION权限.
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.
这篇关于如何以编程方式查找Android设备的MAC地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!