Android 常用工具类之DeviceInfoUtil
public class DeviceInfoUtil { private static WifiManager wifiManager = null; // wifi是否已连接 public static boolean isWifi(Context context) { wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); try { WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiManager.isWifiEnabled() && wifiInfo.getSSID() != null) { return true; } } catch (Exception e) { } return false; } // 获取ipv4地址 public static String getIpv4(Context context) { if (isWifi(context) && wifiManager != null) { int ip = wifiManager.getConnectionInfo().getIpAddress(); return (ip & 0xFF) + "." + ((ip >> 8) & 0xFF) + "." + ((ip >> 16) & 0xFF) + "." + ((ip >> 24) & 0xFF); } return null; } }