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;
    }
}

 

相关文章:

  • 2021-09-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-04
  • 2021-11-24
  • 2021-07-10
  • 2021-11-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2021-10-21
  • 2021-11-30
相关资源
相似解决方案