当前位置:首页 > 操作系统 > MacOs

如何以编程方式查找Android设备的MAC地址

我如何通过编程方式获取Android设备的Mac Id.我已经完成了IMIE Code,我知道如何手动检查设备上的Mac ID,但不知道如何以编程方式查找.

解决方法:

<code>WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String macAddress = wInfo.getMacAddress(); 
</code>

此外,在清单文件中添加以下权限

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

请参考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.


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐