获取手机的mac地址
与IP不同,MAC是指连接WIFI使用的无线网卡的物理地址,这个地址是唯一并且不可变更的。
没有开启wifi能够获取到Mac地址只是获取的ip为0,当然wifi未连接状态下是肯定没有IP分配的。具体看看下面: <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
//在wifi未开启状态下,仍然可以获取MAC地址,但是IP地址必须在已连接状态下否则为0
String macAddress = null, ip = null;
WifiManager wifiMgr = (WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiInfo info = (null == wifiMgr ? null : wifiMgr.getConnectionInfo());
if (null != info) {
macAddress = info.getMacAddress();
ip = Integer.toString(info.getIpAddress());
}
System.out.println("mac:" + macAddress + ",ip:" + ip);
获得MAC方法二: public StringgetLocalMacAddress() { WifiManager wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); return info.getMacAddress(); }
相关推荐
Micusd 2020-11-19
cheidou 2020-11-19
星马殇 2020-11-18
Echodat 2020-10-08
flyToSkyL 2020-09-11
zjc 2020-09-03
阳光普照 2020-09-01
十年砍柴 2020-08-30
猪猪侠喜欢躲猫猫 2020-08-17
ladewang 2020-08-17
渣渣灰 2020-08-13
blankt 2020-08-15
vickay 2020-08-09
TinyDolphin 2020-08-09
山兔与孟婆 2020-08-09
longjing 2020-08-07
xiaogoua 2020-08-06