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

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

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

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

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

1.public String getLocalIpAddress() {   2.        try {   3.            for (Enumeration<NetworkInterface> en = NetworkInterface   4.                    .getNetworkInterfaces(); en.hasMoreElements();) {   5.                NetworkInterface intf = en.nextElement();   6.                for (Enumeration<InetAddress> enumIpAddr = intf   7.                        .getInetAddresses(); enumIpAddr.hasMoreElements();) {   8.                    InetAddress inetAddress = enumIpAddr.nextElement();   9.                    if (!inetAddress.isLoopbackAddress()) {   10.                        return inetAddress.getHostAddress().toString();   11.                    }   12.                }   13.            }   14.        } catch (SocketException ex) {   15.            Log.e("WifiPreference IpAddress", ex.toString());   16.        }   17.        return null;   18.    }  


更多相关文章

  1. LayoutInflater.inflate()方法的介绍
  2. android 笔记 --- 自定义Android主题风格theme.xml方法
  3. android工程下运行main方法的配置方法
  4. Android Studio无法新建创建android工程解决方法
  5. Android Studio设置主题 和 不支持中文的问题解决方法
  6. Flutter下载更新App的方法示例
  7. android map的使用方法

随机推荐

  1. 字符串压缩 牛客网 程序员面试金典 C++ P
  2. MPRIS + Python (dbus):读写属性
  3. 将类对象转换为JSON Python - EasyPost
  4. 名称`posix`在何处/如何通过import语句解
  5. python解压zip脚本
  6. 机器学习、Python和数学学习资料汇总
  7. 计算机视觉相关代码片段(Python)
  8. [python]python学习笔记(七)——加密
  9. Django的模型。在多个模型类和管理中关联
  10. 如何强制python打印指定时区的numpy date