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


    protected InetAddress getLocalInetAddress() {        InetAddress ip = null;        try {            Enumeration<NetworkInterface> en_netInterface = NetworkInterface.getNetworkInterfaces();            while (en_netInterface.hasMoreElements()) {                NetworkInterface ni = (NetworkInterface) en_netInterface.nextElement();                Enumeration<InetAddress> en_ip = ni.getInetAddresses();                while (en_ip.hasMoreElements()) {                    ip = en_ip.nextElement();                    if (!ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1)                        break;                    else                        ip = null;                }                if (ip != null) {                    break;                }            }        } catch (SocketException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }        return ip;    }    protected String getMacAddress() /* throws UnknownHostException */{        String strMacAddr = null;        try {            InetAddress ip = getLocalInetAddress();            byte[] b = NetworkInterface.getByInetAddress(ip).getHardwareAddress();            StringBuffer buffer = new StringBuffer();            for (int i = 0; i < b.length; i++) {                if (i != 0) {                    buffer.append('-');                }                String str = Integer.toHexString(b[i] & 0xFF);                buffer.append(str.length() == 1 ? 0 + str : str);            }            strMacAddr = buffer.toString().toUpperCase();        } catch (Exception e) {            // TODO Auto-generated catch block            e.printStackTrace();        }        return strMacAddr;    }

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Activity的启动模式
  2. Android内存泄漏终极解决篇(上)
  3. 测试横竖屏切换时activity 的生命周期
  4. Android--高效地加载大图片
  5. Android(安卓)性能优化之使用MAT分析内存
  6. android 照相
  7. Android(安卓)日历开发教程[五]
  8. Android(安卓)Binder机制浅析及AIDL的使
  9. Android(安卓)Studio的使用
  10. Android消息通知-Notification