版权声明:转载请@我原创地址 https://blog.csdn.net/weixin_39706415/article/details/83691294
携带获取失败处理
/**
* 当前的mac地址
*
* @return String mac
*/
@SuppressLint("HardwareIds")
private static String getMacAddress() {
try {
WifiManager wifiMan = (WifiManager) MyApplication.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
assert wifiMan != null;
WifiInfo info = wifiMan.getConnectionInfo();
String mac = "";
if (null != info) {
mac = (info.getMacAddress()).replaceAll(":", "-");
}
return defaultMac(mac);
} catch (Exception ignored) {
}
return defaultMac("");
}
private static String defaultMac(String mac) {
if ("".equals(mac) || mac == null) {
return "02:00:00:00:00:00";
} else {
return mac;
}
}
项目使用截图