/**app
* 獲取手機端的ip.net
* ip
* @return get
*/it
public static String getIp()io
{wifi
WifiManager wifiMgr = (WifiManager) application.getGlobeContext()static
.getSystemService(Context.WIFI_SERVICE);vi
if (isWifiEnabled())手機端
{
int ipAsInt = wifiMgr.getConnectionInfo().getIpAddress();
if (ipAsInt == 0)
{
return null;
} else
{
return intToInet(ipAsInt).getHostAddress();
}
} else
{
return null;
}
}
/**
* 是否Wifi可用
*
* @return
*/
public static boolean isWifiEnabled()
{
WifiManager wifiMgr = (WifiManager) Xs8_Application.getGlobalContext()
.getSystemService(Context.WIFI_SERVICE);
if (wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED)
{
ConnectivityManager connManager = (ConnectivityManager) Xs8_Application
.getGlobeContext().getSystemService(
Context.CONNECTIVITY_SERVICE);
NetworkInfo wifiInfo = connManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
return wifiInfo.isConnected();
} else
{
return false;
}
}
public static byte byteOfInt(int value, int which)
{
int shift = which * 8;
return (byte) (value >> shift);
}
public static InetAddress intToInet(int value)
{
byte[] bytes = new byte[4];
for (int i = 0; i < 4; i++)
{
bytes[i] = byteOfInt(value, i);
}
try
{
return InetAddress.getByAddress(bytes);
} catch (Exception e)
{
// This only happens if the byte array has a bad length
return null;
}
}