1、Android  获取本机Mac 地址方法:

  

    需要在AndroidManifest.xml文件中添加权限:

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

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

 

Java代码  
public String getLocalMacAddress() {   
        WifiManager wifi = (WifiManager)           getSystemService(Context.WIFI_SERVICE);   
        WifiInfo info = wifi.getConnectionInfo();   
        return info.getMacAddress();   
    }              

 

2、Android 获取本机IP地址方法:

Java代码  
 
public String getLocalIpAddress() {   
        try {   
            for (Enumeration<NetworkInterface> en = NetworkInterface   
                    .getNetworkInterfaces(); en.hasMoreElements();) {   
                NetworkInterface intf = en.nextElement();   
                for (Enumeration<InetAddress> enumIpAddr = intf   
                        .getInetAddresses(); enumIpAddr.hasMoreElements();) {   
                    InetAddress inetAddress = enumIpAddr.nextElement();   
                    if (!inetAddress.isLoopbackAddress()) {   
                        return inetAddress.getHostAddress().toString();   
                    }   
                }   
            }   
        } catch (SocketException ex) {   
            Log.e("WifiPreference IpAddress", ex.toString());   
        }   
        return null;   
    }  

 

posted on 2013-09-02 15:54  暖 暖  阅读(434)  评论(0编辑  收藏  举报