android 获取wifi mac 地址的代码

public String macAddress = "";//wifi物理地址
public void getWifiMacAddress(){
	    	final WifiManager wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
	    	if(wifi == null){
	    		return;
	    	}
	    	WifiInfo info = wifi.getConnectionInfo();
	    	this.macAddress = info.getMacAddress();
	    	if(this.macAddress == null && !wifi.isWifiEnabled()){
	    		new Thread(){
	    			@Override
	    			public void run(){
	    				wifi.setWifiEnabled(true);
	    				for(int i = 0 ; i < 10 ; i ++){
	    					WifiInfo info = wifi.getConnectionInfo();
	    			    	macAddress = info.getMacAddress();
	    			    	if(macAddress != null){
	    			    		break;
	    			    	}
	    			    	try {
								Thread.sleep(500);
							} catch (InterruptedException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
	    				}
	    				wifi.setWifiEnabled(false);
	    			}
	    		}.start();
	    		
	    	}
	    }

mac

相关推荐